Andrej Tozon's blog

In the Attic

NAVIGATION - SEARCH

Silverlight 2.0: Creating a basic animation through code

In my previous Silverlight post, I mentioned Silverlight 2.0 API now allows creating animations through code. While this wasn't possible with Silverlight 1.1 Alpha [you would have to create of piece of Xaml, declaring a storyboard with all animations markup, then load it into a Storyboard object by using XamlReader.Load() method], Silverlight 2.0 now makes it pretty easy.

The following animation code will create very basic fade out effect for given element, animating the Opacity property from 1 to 0 in one second:

private DoubleAnimation CreateFadeOutAnimation(string elementName)
{
    DoubleAnimation animation = new DoubleAnimation();
    Storyboard.SetTargetName(animation, elementName);
    Storyboard.SetTargetProperty(animation, "Opacity");
    animation.To = 0;
    animation.Duration = new Duration(TimeSpan.FromSeconds(1));
    return animation;
}
To start this animation, you'll have to add it to a new storyboard first:
Storyboard sb = new Storyboard();
sb.Children.Add(CreateFadeOutAnimation("myElement"));
sb.Duration = new Duration(TimeSpan.FromSeconds(1));
sb.Completed += new EventHandler(sb_Completed);
LayoutRoot.Resources.Add(sb);
sb.Begin();

The "myElement" above is the name of an visual element with this name, which has to exist in the context of the storyboard for it see it. Storyboard is added to the LayoutRoot's resources [LayoutRoot is the name of a default root Grid in Silverlight]. Instead of passing just a name of an element, you could as well pass in the actual element you're animating.

Note the Completed event hookup up there. This is because we want to stop and remove the animation from the resources when animation is done to clean things up a bit. Here's the handler:

void sb_Completed(object sender, EventArgs e)
{
Storyboard sb = (Storyboard)sender; sb.Stop(); this.Resources.Remove(sb); }

That's it. Of course you can add as many animations to the storyboard as you want - animating different elements at the same time, adding different animations, etc... In further posts we might add some more complexity to this basic sample.

Mix'n'stuff

As expected, a lot of stuff was shown and discussed on the MIX08 keynote today:

  • eight - Internet Explorer 8 Beta 1 (download): better standards compliance, backward compatible mode, faster faster JavaScript implementation, embedded debugging tools, "activities" and "webslices" (custom extensions, deliverable simply by hacking up a couple of rows of XML),. ...
  • Silverlight 2.0 Beta 1 (download): it's here! With only 4.3MB in size, it delivers highly anticipated UI controls, along with a new testing framework, including tests for all Silverlight controls. Supports isolated storage for offline caching. Plus, Silverlight 2.0 now ships with a non-commercial Go-Live license and will also run on Nokia [Symbian] phones. Finally, if you've done any work with Silverlight 1.1, you're in for a serious code rewriting, as there's a lot of breaking changes in the code base. [That's, however, a good thing, because these changes bring Silverlight's programming model much closer to the the one in WPF]
  • Expression Blend 2.5 March 2008 Preview (download): Silverlight 2.0 Support
  • Silverlight Tools Beta 1 for Visual Studio 2008 (download): Add-on to Visual Studio for Silverlight 2.0 Beta 1 development. Better designer experience, although far from being nice as in Expression Blend.
  • Sea Dragon in action - Deep Zoom: take a look: Hard Rock Memorabilia [a bit quirky at the moment, I'm afraid] Want to make your own Deep Zoom creation? Download Deep Zoom Composer preview. And you can start with this User Guide.
  • The future of WPF: new controls, performance improvements, etc...

Watch the MIX08 keynote recording here.

[Update: here's a great preview of Silverlight 2.0 Beta 1 controls in action by Kathy Kam. Note that these controls are available in source code w/ full unit tests]

Express your love with Silverlight :)

Want to impress your loved one with a Valentine's card tomorrow? Why not sending her/him a Silverlight Valentines? Silverlight and Windows Live teams created this card template for you to modify it and share your love. The process only takes four steps - you can pick a photo from either Windows Live Spaces or Flickr, enter a short text or poem, choose accompanying music and send the card.

image

A cool example of integrating other services with Silverlight... Just the right one to end up on CodePlex or MSDN Code Gallery someday ;)

Tick, tock... Silverlight Challenge: one week left

Just a quick reminder: 1st European Silverlight Challenge is entering the finishing line. As announced, the competition ends next Monday, which still gives you plenty of time to polish your applications and give them some finishing touches. When ready, don't forget to submit your app on local competition site (click here for Slovenian site). Note: you'll have to register and log in first to submit your entry.

Starting today, Silverlight v1.0 is also available through Windows Update, as an optional update.

Wait, there's more... also available through Windows Update from today, are updates for all Expression products, including service packs.

Just keep 'em coming...

Let Silverlight shine on YOU!

Join developers all around Europe in the ultimate Silverlight Challenge. Yes, the 1st European Silverlight Challenge is on and Slovenia is one of the many countries participating. For more information  head over to Slovenian and European competition site, read the official rules and start your Visual Studio. Also, feel free to discuss the Challenge and Silverlight on SLODUG's forums.

1st European Silverlight Challenge ends on January 28th, 2008. The spotlight is on you!

"Call me 2.0... Silverlight 2.0"

Right... no more "Mister 1.1", no more Alpha - Silverlight 2.0 Beta is expected in Q1 2008 (@Mix?), bringing a rich set of controls (including DataGrid!), higher level of WPF UI framework, more connectivity options and richer BCL support. This Beta is expected to include a Go-Live license.

Read the full announcement on ScottGu's blog.

While on a subject, Silverlight 1.1 Tools Alpha for Visual Studio 2008 [RTM] were released a couple of days ago.