I'm really pleased to share that I will be presenting a session on Silverlight animation at MIX 2009. If you're at the conference, keep an eye out for me or stop by the session and say 'hi'. I had the pleasure of attending MIX in 2008, and it really is an amazing learning opportunity - definitely one not to be missed if Silverlight is your thing.

Here are the details of my session:

Principles of Microsoft Silverlight Animation
Come and learn the fundamentals of Silverlight animation. Start at the beginning with a review of storyboards and keyframes, and then break free from storyboards and explore procedural animations. This is where the rubber meets the road and your objects come to life-vectors, frame-based animations, collisions, particle systems, and VR objects.

I spent some time this weekend getting an article written up for the Silverlightshow Write and win contest. You can see the article here.

I tackled the problem of how to deliver files from within a Silverlight application to an end-user, by leveraging some JavaScript and HTML.

Be sure to check it out!

There have been plenty of posts describing how inefficient the zip compression is on XAP files, and how it's possible to shrink the size of a XAP by simply unzipping and rezipping using a utility like WinZip.

Another tool we've tested that has now become a regular part of our toolbox is PNGGauntlet, which is a terrific, free utility that can shrink the file size of PNG files. Learn more about it here.

To give you a real world example, we have an application we're going to launch this upcoming week. At code complete, the XAP file size was 146K. After using PNGGauntlet on the images in the app, the size dropped to 122K. After unzipping and rezipping, the app weighs in at 89K. That's a 61% reduction in filesize by doing almost nothing on my part. While the change is usually not that drastic, it's definitely woth the minimal effort on my part to see what kind of reduction I can get.

There's a site online I've seen a few times through the years, and always thought it was cool. It shows a photo of Seattle's waterfront taken in 1907, and there's a slider you can move to see it in 2002. I emailed the creator of the site, Alan Taylor, and got permission to do a Silverlight version, which can be seen here.

The idea behind the Silverlight approach to the application is pretty straightforward - create both image layers, a clipping path, and a draggable handle. As the handle is manipulated, adjust the clipping path accordingly.

Along those lines, this is what my XAML looks like:

 
<Canvas x:Name="LayoutRoot" Background="#FF000000" Width="850" Height="243">
    	<Image Height="173" x:Name="_2002" Width="850" Canvas.Top="18"
          Source="sea_wft_850_2002.jpg"
          Stretch="None"/>
    	<Canvas Height="173" Width="850" Canvas.Top="18" x:Name="Then">
    	<Image Height="173" x:Name="_1907" Width="850" Source="sea_wft_850_1907.jpg"
             Stretch="None"/>
    	    <Canvas.Clip>
                <PathGeometry>
                    <PathFigure IsClosed="true">
                        <LineSegment x:Name="PathTopLeft" Point="0,0"/>
                        <LineSegment x:Name="PathTopRight" Point="8,0"/>
                        <LineSegment x:Name="PathBottomRight" Point="8,173"/>
                        <LineSegment x:Name="PathBottomLeft" Point="0,173"/>
                    </PathFigure>
                </PathGeometry>
            </Canvas.Clip>
	</Canvas>
    	<Image Height="243" x:Name="Handle" Width="16" Source="glass3.png" Stretch="None"
          Canvas.Top="-2"/>
</Canvas>

Notice the <Canvas.Clip> code, which creates a clipping path out of a path constructed from line segments. In this case, it's a rectangle.

The code-behind starts out by declaring the variables used for dragging, as well as two points - one to store the top right of the clipping path, and the other to store the bottom right. The left side of the clipping region does not move.

 
private bool IsMouseCaptured;
private Point MousePosition;
private Point TopRightPoint = new Point();
private Point BottomRightPoint = new Point();
 

Inside the Page() constructor, I set the default Y values for my point objects, and create a few event listeners. The "Handle" object is the handle that the user manipulates to change the view.

 
TopRightPoint.Y = 0;
BottomRightPoint.Y = 173;
 
Handle.MouseLeftButtonDown += new MouseButtonEventHandler(Handle_MouseLeftButtonDown);
Handle.MouseLeftButtonUp += new MouseButtonEventHandler(Handle_MouseLeftButtonUp);
Handle.MouseMove += new MouseEventHandler(Handle_MouseMove);
 

The mouse up and mouse down handlers contain pretty standard drag and drop code, as does the mouse move handler. However, the mouse move code was also augmented with the code that updates the clipping path. The following code shows how that is done. It starts out by checking to see if the handle has reached either end of it's range. If it's within range, the right side of the clipping path is calculated based on the position of the handle. Then the handle position is updated, as are the clipping path points.

 
if (NewLeft >= 0 && NewLeft <= LayoutRoot.Width - Handle.Width)
{
    TopRightPoint.X = BottomRightPoint.X = NewLeft + 8;
    Item.SetValue(Canvas.LeftProperty, NewLeft);
    PathTopRight.Point = new Point(NewLeft + 8, 0);
    PathBottomRight.Point = new Point(NewLeft + 8, 173);
}
 

That's all there is to it! One of the things I like about implementing this technique in Silverlight is that you instantly have a version that works cross-platform, cross-browser. No need to worry about the nuances between browsers. You'll notice that the original version does not work in Firefox, for example. When we're building applications at work, we always test in IE6, IE7, IE8, FF2, FF3, and on the Mac, and I can't recall the Silverlight bits of our projects ever having and consistency or look and feel issues like the HTML portions of pages often do, due to styling issues and what not.

If you want to see the final project, you can download the code here.

After I saw the announcement of the MIX10K Challenge, I knew I wanted to put something together. I spent some time thinking it over, and created an example that leverages code found in my book.

My entry includes physics, collisions, drag and drop, throwing, controls, etc. As it turned out, I had some room to spare too - weighed in at 7.5K. As with other entry authors, if you like my entry, I'd love your vote/rating.

Thanks!

I stumbled upon this the other day, though in hindsight, it's obvious that it would be there. Just as with the hyperlinks in HTML, you can use the hyperlink in Silverlight to invoke the user's default mail client. This is commonly referred to as a "mailto" link.

To do it, just set the hyperlink's "NavigateUri" property to "mailto:" and add the email address. To add a subject, follow up the email address with a "?Subject=" and whatever you'd like the default subject to be. For example, the following code would open up the client's default email program with a mail to the address you fill in.

NavigateUri="mailto:NAME@DOMAIN.COM?Subject=Silverlight Hyperlink"

Very useful for sharing a site via a "Send to a friend" link or something similar. In that case, you would want to omit the "NAME@DOMAIN.COM" part shown above to allow the user to fill it in on their own.

Probably also very useful for "Contact Us" or "Send Feedback" links since the spambots probably can't see the content inside a Silverlight application.

In case anybody needs it, here's a Silverlight/XAML gauge object.

The downloadable project includes a single gauge object which is instanced twice so you can see how to change the color of the gradient background. My trial period for Design expired, so I did all of the design work in Blend. There's also a storyboard to "idle" and "rev" the needle in the gauge. If you elect to make your own animation or use code to animate the needle, remove the storyboard in there to crunch down the file size. I could also see this one potentially being used as a download graphic.

Here's what the project looks like:

Gauges Project










And you can see them live here. Enjoy.

Just wanted to take a moment and talk about a recent project I did that went live earlier this week in conjunction with the PDC conference.

Modelsremixed.com is a Silverlight-based site that supports Microsoft's "Oslo". You can learn more about "Oslo" on the site. All of the animations were done by hand in Blend. There's a couple of things I love about the site. The design is simple - super clean, but looks cool and doesn't get in the way. The other aspect of the site I love is the video section. This is the most complete video player I've authored to date. It combines 4 streaming sources and one progressive download. Corey Schuman's video slider saved me a ton of time (I still remember the first one I wrote in Silverlight 1 - no comparison). All of the controls have tooltips, and the video player includes an embeddable version and integrated sharing options (Digg, Del.icio.us, etc.).

Check it out and let me know what you think.

Amazon has finally updated the listing for my forthcoming Silverlight 2 book. The total page count landed at 448, and the release date has been moved up to November 3rd - Amazon was reporting 300 pages and November 8th for a looong time.

So with that in mind, as we enter the final week before the book releases, here's a peek at the table of contents.

In keeping with some of my prior posts, here's some low-quality sneak peaks at a few more of the projects too:

Some collisions with multiple angled surfaces can be seen here.

Last time, I posted a horizontal carousel. Here is a vertical version.

Here is an example of a chain pull.

And finally, two particle system examples. A particle fountain, and a node garden.

As always, apologies for the low res, low frame rate videos, but I need to minimize the file size as much as possible.

Wow, what a crazy week. I had two Silverlight projects due at work. One was developed in beta 2, and had to be compiled in RC0, and both versions are wrapped on the page. Then on Wednesday, I converted my development environment to the RTM version. Took longer than I anticipated, but managed to knock out the next project fully in the RTM.

I have also converted some of the projects I posted here.

The Bird Hunt game is here.

Tank Combat is here.

Etch-A-Sketch is here.

The Filmstrip gallery is here.

The modified Filmstrip (auto running) is here.

For the code/explanation of the filmstrip effects, you can check out the blog post here.

I have some ideas for some additional projects to put up to demonstrate some different techniques, and I will have more information about my book and some additional project movies soon. Only a couple of weeks until it's out!