WPF the same as Silverlight? Don't think so...

Published 4 Mar 2010 9:57 AM

Currently working on courseware for both Silverlight and WPF concurrently (perhaps not the wisest recent decision). My theory was (and note the past tense) that they both use XAML to describe their UIs, so how far apart could they be? I have spent the better part of a week creating a simple (actually, not simple at all) demo project to show off some of the simple controls in WPF and Silverlight (you know the drill: Button, TextBox, Slider, CheckBox, RadioButton--all the old favorites). Turns out that the behavior is very, very different between WPF and Silverlight, often in mystifying ways. Things that work in one environment aren't available in the other. The cut-down .NET Framework in Silverlight is far more limited than you would imagine (although it seems like a miracle that it works at all.)

My suggestion, if you're creating an app that you want to run both in WPF and Silverlight (and I'm not sure why anyone except courseware authors would do this): Create the Silverlight version first. Because its behavior is so limited, you're better off converting from Silverlight to WPF than the other way around. Beware, however, that some things work in Silverlight and not in WPF, so there are issues no matter which direction you go. (For example, in Silverlight, the MediaElement control will play a WMV file stored as a resource in the current project. I cannot get the WPF version to play the video--I ended up using an external file path instead.)

Do not fall into the trap: WPF and Silverlight may look and feel similar, but in fact, they're very different, with distinct issues and learning curves.

by KenG