Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How portable is Silverlight code to WPF?

In Silverlight I noticed that the code-behind Page class inherits from UserControl:

public partial class Page : UserControl

In WPF the code-behind Page Class inherits from Page:

public partial class Page1 : Page

I was thinking that Silverlight, being a subset of WPF, you would be able to copy large blocks of Silverlight code into WPF later and vice versa. But differences like this at such a base level indicate that this will not be the case.

Is this just an anomaly or are complex Silverlight applications going to be pretty much unportable to WPF without significant changes?

like image 442
Edward Tanguay Avatar asked Jan 27 '09 00:01

Edward Tanguay


3 Answers

The way I understand it is that aside from both using XAML, Silverlight and WPF are essentially different. There does appear to be cross-pollination between them though, so when Silverlight shipped without things like WrapPanel, someone wrote their own implementation in Silverlight (and it eventually got added to the Silverlight Toolkit).

Dont expect to copy and paste from WPF unless it's trivial code. Things like data binding are slightly different in Silverlight (eg: no binding to other elements). Most of the time there are workarounds though.

like image 90
geofftnz Avatar answered Nov 12 '22 11:11

geofftnz


Have a look at this article, it talks about many of the things you need to do to port from SL to WPF. There is also a link in that article to Scott Gu's blog on the subject; however, this article talks about some differences not mentioned on The Gu's blog.

like image 43
palehorse Avatar answered Nov 12 '22 13:11

palehorse


Silverlight is designed to be a compatible subset of WPF (at least where it "makes sense"). This means that porting an app from Silverlight to WPF should be relatively straight-forward. Going in the other direction (WPF -> Silverlight) is likely to be significantly more challenging.

The example that you give in your question illustrates this point; the Page class that is used in the default WPF project template does not exist in Silverlight. But the UserControl class exists in both. So you can copy and paste the xaml and code from your Silverlight application which derives from UserControl into your WPF application without any problem.

There are certain parts of Silverlight that are not really compatible with WPF, for example all of the HTML DOM Bridge stuff would not make any sense in a WPF application, so it is not there. Also the MediaElement class is significantly different.

like image 1
KeithMahoney Avatar answered Nov 12 '22 12:11

KeithMahoney