Blog

10 Things Developers Will Love About Silverlight 5

During the Silverlight Firestarter Scott Guthrie gave a preview of Silverlight 5. Based on the list of new features it seems Silverlight 5 will be at least as significant of an update from SL 4 than SL 4 was from SL3.

In this article I'm looking at the 10 most important things any Silverlight developer - like myself - should be excited about in this upcoming release.

1. Debug Data Binding Expressions by Using Breakpoints in XAML

In Silverlight 4 data binding expressions are great... when you've set them up correctly that is. When you want to debug them it's a real pain to do so. In Silverlight 4 the two ways to debug data binding expressions are:

  • either to look at the debug output window dump and hope that some relevant information is revealed
  • or set up dummy ValueConverters so you could your break when the binding actually occurs - if it occurs!

With the ability to be able to place break points in the XAML on binding expressions, none of this hacking will be needed, saving lots of time and frustration. When breaking on a binding a BindingState object is shown in the Locals windows that returns all information on the binding that should help solve the issue with it.

2. Animations Made Easy with Transitions

Animations are really powerful in Silverlight, the only problem with them is that they're complicated to write. You need to have StoryBoards, Animations within those and creating and configuring just a simple animation is about 10-15 lines of code both in code behind and XAML.

Silverlight 5 introduces transitions that make defining animations possible in much fewer lines of code. Transitions seem to be wrapper classes around animations. Now instead of having to specify an animation from scratch, you can easily configure the most commonly animated element properties (e.g. opacity, x/y start and end offsets, easing function) on an easy to interpret class interface:

<LoadTransition StartXOffset="300" GeneratedDuration="0:0:1.0" StartOpacity="0.2">
   <LoadTransition.GeneratedEasingFunction><CircleEase/></LoadTransition.GeneratedEasingFunction>
</LoadTransition>

3. Navigating Up the Visual Tree in Bindings using RelativeSource and Mode=FindAncestor

When using DataTemplates in specifying list items, it would sometimes be great to be able to "reach outside" of the model's DataContext to another object in the visual tree and use that object as a binding. Say you have ListBox showing off Book items in it's DataTemplate and you'd like to have a ListBox inside of each of these book items that would show the deals for the book. The problem is, the Book model has no notion of Deals, the Deals object is somewhere else in the visual tree.

In Silverlight 5, this problem can be solved by using a RelativeSource, Mode=FindAncestor expression:

<ComboBox ItemTemplate={StaticResource DealItemTemplate} ItemsSource="{Binding DataContext.Deals, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}"/>

This code sets the relative data source to the first ancestor item of the element that's of type UserControl and the ComboBox's ItemSource is set to that UserControl's Deals property. Binding to parent elements in the visual tree just got so much easier!

4. Binding View Events to the ViewModel Using Custom Markup Extensions

A small, but frequently annoying pain point with Silverlight 4 was that binding an event on a control to the ViewModel wasn't that easy to do. The two possible ways of working around this were:

  • Use Triggers to bind to Commands in the ViewModel. This solution involved lots of XAML and the need to define Commands on the ViewModel - quite a complicated solution.
  • Define event handlers and invoke methods on the ViewModel in the event handler. This solution meant quite tight coupling between the View and ViewModel and introduced a possible error source if the invoking wasn't done correctly.

.

In Silverlight 5 custom markup extenstions are supported and binding to invoking a method in the ViewModel is possible with a single line of code similar to the following:

<ListBox SelectionChanged="{MyMethodBinding:Invoke Method=OnSelectCategory}"/>

The code above invokes the OnSelectCategory method on the MyMethodBinding class - nice and simple!

5. Changing Styles Runtime By Binding in Style Setters

I've blogged about how painful it is to modify Styles during runtime in Silverlight 4 because once a Style is applied to an element in the visual tree, it can't be modified any more.

Silverlight 5, however is making this matter much less painful by enabling bindings in Style setters. This means that styles can now be changed on the fly just by changing the object that they're binded to. The binding is set up exactly the way one would expect:

<Style x:Key="AccentCircles" TargetType="Ellipse">
   <Setter Property="Fill" Value="{Binding MyCustomBrush, Source={StaticResource MyCustomColorSettings}"/>
</Style>

I can see this feature be especially useful for applications where re-theming is possible. Combined with implicit styles, this will mean that restyling a complete application will be really easy from now on!

6. Networking No Longer Happening on the UI Thread

Realtime systems such as trading systems are constantly suffering from the fact that networking events are always marshalled back to the UI thread at some point in the networking stack. This means that up to Silverlight 4 if the UI thread was busy rendering, it was blocking networking requests (see Ray Booysen's article on this issue). This issue also affects Windows Phone 7 as whenever an application is accessing the network

In Silverlight 5 this issue is finally addressed meaning much less effort (if any) will have to be invested in freeing the UI thread - and now real time applications can have animations and other heavyweight UI interactions enabled!

7. Vector Based Printing

Currently it is only possible to print from bitmaps in Silverlight 4, which is not ideal in most cases. Silverlight 5 will introduce support for Postscript vector printing. There aren't many details out on this feature, however it already sounds promising!

8. HTML Content and Additional Permissions Within Trusted Silverlight Application

Unfortunately raw HTML content won't be viewable in all Silverlight applications, not even in Silverlight 5. Fortunately this will be possible in a subset of them, if they are running as trusted applications. To enable this trusted mode, a group policy registry key and an application certificate need to be set up.

Once this done, the application can view HTML contents as a web browser control, read/write the users My Documents folder, launch Office and access devices by COM calls.

9. 3D API

Silverlight 5 is introducing a 3D API. This API will be low level and will be GPU accelerated for good performance. This means now it will be possible to create performant 3D applications for the web as well (this is already possible on the desktop with WPF and on Windows Phone with XNA) The demos showcased were quite impressive, lots of cool 3D visualizations to come to the platform!

10. Smaller Enhancements: Text Clarity and Performance Improvements

Text clarity has always been an issue with Silverlight compared to WPF or even Flash. Silverlight 5 is now improving this by implementing Pixel Snapping. OpenType support is also being enhanced - looks like Silverlight is getting more mature in text handling as well!

Smaller performance improvements are being implemented, such as faster startup time, better text layout performance and also better performance when running within IE9 using hardware rendering.

When Can I Try It?

Unfortunately none of the above can be tested at the moment as this was only a development preview on the event. However the timeline for Silverlight 5 has been released: according to this Silverlight 5 Beta is expected to ship in spring 2011 (probably on MIX '11) and the final version will arrive afterwards in 2011.

Charting in Silverlight / WPF? If you need a component delivering exceptional performance, is easy style and extend, then give the free version of Visiblox a try!
 

Comments

Nice post Gergely, a succinct round up of new technology releases is always good.

P.S. I wonder how many people will get Scott Gu's tattoo!

 
Posted by Drew Forster

[...] Scott Guthrie gave a preview of the new features being developed in Silverlight 5. I’ve written an article om the 10 most important new features Silverlight developers should be excited about. These are the [...]

 

I've blasted Silverlight as I've worked with it, but if that 3D API is pretty easy to use, Silverlight might be on to something.

 
Posted by infocyde

This is really the prominent features in Silverlight 5. PS: At Silverlight Firestarter, everyone was surprised when see the Scott Gu's tattoo! I'm, too :)

 
Posted by bindoremon

on point 9 you say that this has already been possible in WPF. Can you clarify this? From the video they talk about using vertex shaders, do we have vertex shaders in wpf, I thought we only had pixel shaders.

 
Posted by Peter

Thanks for the comments.

Peter: there's already a 3D API in WPF, in Silverlight 4 there's still none. I don't know how different the Silverlight 5 3D API will be from the existing WPF one. Unless someone at Microsoft will give any details on this, I think we'll have to wait till the beta release to find out!

 
Posted by Gergely Orosz

[...] 10 Things Developers Will Love About Silverlight 5 - Gergely Orosz gives a quick rundown of 10 of the top features that will be included in the forthcoming Silverlight 5 releases [...]

 

[...] Concernant Silverlight, VisiBlox nous explique les 10 nouveautés qui feront la joie des développeurs, dans Silverlight 5.  Lien [...]

 

[...] at some point in the first half of 2011. The new features, which my colleague Gergely details in a recent blog post, are geared towards media and business applications, which in my opinion is a good thing. This [...]

 

[...] Visiblox™ | 10 Things Developers Will Love About Silverlight 5: [...]

 

Post a comment