The last one-and-a-half to two years I have been developing WPF applications. A few weeks ago I decided to go and start playing around with Silverlight 2.0. After all on the surface it looks almost the same as WPF. And this also the pitfall because as a WPF developer it looks so much like WPF you tend to think it is WPF.
Fortunately Microsoft guides you through the differences on MSDN: Silverlight WPF Compatibility. This list most of the differences. Some topics you take for granted like the lack of 3D graphics in Silverlight. Some things that are annoying (at least I ran into them) but yet workable like: no ResourceDictionaries, no DynamicResources, no UI to UI element binding, or no binding to XML.
But it lists also more irritating differences:
- No possibility for custom routed events, no preview events and simply fewer events (including the absence of the drag drop events).
- No CollectionView or CollectionViewSource.
- No Triggers. Silverlight uses a VisualStateManager which is driven from code. This is something completely new if you’re used to developing WPF stuff where you could simply use triggers to use a different appearance for different states. On the internet you can find what is ‘wrong‘ with the VisualStateManager from a WPF perspective. I found a blogpost of John Gossman describing how these two models (of WPF and of Silverlight) can be (and seem to be) merged by Microsoft in the future.
- No CoerceVallueCallback for dependency properties.
But the real reason for this post (besides that I didn’t find the MSDN page directly) is that I ran into some undocumented differences that got me puzzled for a while:
- Some controls such as ListBox and ListBoxItem do not raise the LeftMouseButtonDown event although they do define it.
- ListBox has no ItemContainerGenerator which can be useful to translate a ListBoxItem to a data object.
- The Visibility enumeration only has the values Collapsed and Visible (looks like a boolean to me!). The missing Hidden member can of course be solved by setting the opacity to 0.
- No Adorners.
I hope it will help some of you if you decide to go developing a Silverlight application as a WPF developer. Remember the primary target for Silverlight is to develop Rich Internet Applications and give the users a Rich Internet Experience and to do this it is a very powerful framework. The possibility to develop a full-fledged LOB application has lesser priority and as such requires a little more effort to realize.
I have not yet touched all the different areas (for example not a single service call is made) of Silverlight so if you think I missed an important difference here please comment.
3 comments
Something that will really change your way of programming a client is the way SL more or less forcces you to program asynchronously. It’s not just that you have to subscribe to lots of Completed events, it’s also the way you lock the UI to prevent multi-triggering the job that you are waiting for (e.g. prevent a order to be ordered twice)
Be carefull with using opacity 0 for the WPF-Hidden. It is not the same. WPF-Hidden causes the control to be skipped while rendering; I am not sure whether SL will render the zero opacity control. It might look the same but it might be slower.
LOB’s are on their way! Read about the RIA Service Framework here: http://go.microsoft.com/fwlink/?linkID=144687 or even download it here: http://www.microsoft.com/downloads/details.aspx?FamilyID=76bb3a07-3846-4564-b0c3-27972bcaabce
BTW: some of your annoyances will be solved with version 3 (more 3D and element to element binding)
Erno de Weerd
Erno thanks for the extra info! Obviously there still is a lot to discover for me in SL development.
The zero-opacity vs. hidden is something interesting to dive into. Sometimes you just want to hide an element but still let it use some space (should prevent layout changes when the ‘functional visibility’ is toggled). Maybe I’ll get back to that. 🙂
josd
Actually the ResourceDictionary is there. The only thing that is missing is the possibility to create a merged resource dictionary.
Currently I’m working together with a few colleagues on a LOB application and we’re making good progress even with the in my opinion small irritations.
One of the things we are tackeling at the moment is validation of data entered in the user interface with the limited infrastructure of silverlight. It’s a challenge, but we’re getting there 😉
willemm