WPF Airlines

I often hear of the “Source Code Compatibility” between Silverlight and Windows Presentation Foundation and so today I thought I’d try it out a little bit.

Personally, I don’t view this as;

Take your SL source code, add a few bits and pieces and you have a WPF application. Add a bit of conditional compilation where necessary.

I don’t have a perfect picture of it in my head but I see it more as perhaps;

Build both a Silverlight and a WPF UI. Try and build components that can be built to underpin both. Most of what you’ve got will build/work on both frameworks and then you’ll perhaps have a remaining 10% or so that’s similar but different enough to want to separate out to being WPF/Silverlight specific.

I still think it sounds challenging and I’m not sure how you’d do (e.g.) source code compatibility between Silverlight controls that are using the VSM and WPF controls that aren’t. That feels like a tricky one to get right and I suspect that there are a whole bunch of other areas that need a lot of thought to try and get this to work.

You could argue that you pick a control set that’s common across both Silverlight and WPF ( i.e. the common Microsoft control set and perhaps a 3rd party control set that supports both ) and use those. That might help a whole lot in raising you above the WPF/Silverlight differences.

I can definitely see that you can re-use your knowledge and skills across the 2 frameworks. That’s a given. I can also see that you’d re-use a whole bunch of XAML by just lifting it from one framework to the other, changing a few bits and pieces (like the namespace :-)) and then getting it linked up with some code and running.

Anyway…I wanted to experiment and so I thought that I would port an existing Silverlight application to WPF.

I chose Silverlight Airlines.

On reflection, this was probably a bad choice 🙂 From looking at the source for Silverlight Airlines you can tell ( I think ) that it was written for Silverlight V1.1 rather than Silverlight V2.0 in that it does quite a lot of dynamic loading of XAML rather than use the control model that showed up in V2.0. It’s nicely structured there so you can pretty quickly get to grips with it.

I chose to do what I call a “literal” port of it in the sense that I just took what was there and hacked at it until I had it running on WPF. I made no attempt to do things in any kind of “better” way but just tried to get it across to WPF. There are some specific things around resizing that I don’t think you would do in a world of Grid and so on but the code is all Canvas based from the V1.1 preview.

I’d say that it took me about 60 minutes and of those 60 minutes I reckon I spent around 45 just monkeying around trying to figure out what to set the build option on my XAML files to and why the XAML files weren’t being loaded by Application.LoadComponent and so on.

The last 15 or so minutes were probably spent in a debugger trying to figure out why certain animations weren’t where they were expected to be and switching a few calls to FindName() to look into Resources collections.

I put the source code here for download. This is not my code and so I possibly have no rights to distribute it but it’s a public sample so I figured no-one would mind. If you do mind, mail me and I’ll remove it and update the post.

Here it is running on Vista in all it’s glory 🙂 Don’t worry about the crazy looking colours – that’s just my desktop shining through the glass.

image