Andrej Tozon's blog

In the Attic

NAVIGATION - SEARCH

Experience new Silverlight skins

Corrina Barber posted a cool looking new skin for Silverlight controls, which indeed looks perfect for giving your application a sketchy appearance when in early stages of development.

However, if you don't find the green color she used sketchy enough, it doesn't get any easier to adjust it to your likings. When we're talking about control skins in WPF/Silverlight, we're talking about styles, right? So...

with a simple Search & Replace in the App.Xaml file she posted along with her sample, I changed some of the colors in her skins to get a bit more of a Black & White / Gray appearance:

Silverlight skin 

Now imagine, how much "damage" you could do to this skin with Expression Blend...

Anyway, this is the fourth Silverlight skin she posted and she's not stopping. If not anything else, this is a great inspiration to start creating your own Silverlight skins!

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.

Installing Expression Blend 2.5 March 2008 Preview

If you're considering installing Expression Blend 2.5 March 2008 Preview over Expression Blend 2 December Preview, make sure you uninstall the December Preview first, and then continue with March Preview installation. When doing vice versa, you'll lose some of the "Open in Expression Blend" shortcuts [allowing you to open solutions from Windows Explorer, or open (Silverlight) Pages from Visual Studio 2008].

Open from Explorer
Open from Visual Studio 2008

However, all is not lost if those shortcuts are gone after uninstalling December Preview. Simply repair the March Preview installation and you're back and ready to blend your solutions again.

Repair

First couple of days with Silverlight 2.0 Beta 1

Here's some notes on my first experience with Silverlight 2.0 Beta 1:

Installation

Runtime - quick, smooth. Like it's supposed to be.

Tools for Visual Studio 2008 - if running Alpha version of the tools, you'll have to uninstall it first. During the install, the VS2008 DVD might be required. For more info on this and a way around it, see this BradlyB's blog post.

Controls

Yeah! Loving it. Hey, there's a cool DataGrid control, and a DatePicker. Given that WPF still hasn't got those (out of the box), which technology would you rather pick for your next cool (demo) app? Silverlight or WPF?

If you've just begun learning these new technologies, I'd for sure recommend Silverlight - you're forced to work with a smaller programming model (a subset of that of WPF), and you're inevitably going to pick up some WCF in the process, if your application involves any kind of (disconnected) data.

Animations

With Silverlight's programming model moving closer to what we currently have in WPF, creating animations in Silverlight now feels much more comfortable. No need for creating animations by loading declaration code from Xaml any more; animations and storyboards can now easily be done from code; I'll post some sample code in next posts.

Connectivity

Lots of options here... WCF, HTTP based, JSON, RSS, Atom, ... There's, however, still a few limitations, some of them being: BasicHttpBinding-only for WCF (or no WS-* protocols for Web Services), some types (like XmlElement or XmlNode) can't be used in data contracts.

But... cross-domain service calls are now possible! The dreaded "cross domain call exception" is gone. Well, not entirely true, but if you play nice and/or have control over the service's web site, it's likely you won't bump into that wall again. For all other cases, using server-side proxies still seems like a possible way out.

Also worth noticing is that the managed Downloader class has been removed in favor of the WebClient class, which should offer the same functionality. Similarly, BrowserHttpWebrequest class was replaced with HttpWebRequest class.

Calling services is now asynchronous!

Other

Of course, there's a lot more... Some of the changes will be covered in my next posts on Silverlight 2.0 B1.

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]