How portable is the Silverlight code for WPF?

In Silverlight, I noticed that the default page class inherits from UserControl:

public partial class Page : UserControl 

In WPF, page code by page type is inherited from the page:

 public partial class Page1 : Page 

I thought that Silverlight, as a subset of WPF, you can copy large blocks of Silverlight code into WPF later and vice versa. But differences like this at such a basic level show that this is not so.

Is it just an anomaly or sophisticated Silverlight applications that are largely not migrated to WPF without significant changes?

+7
wpf silverlight
source share
3 answers

I understand that apart from using XAML, Silverlight and WPF are significantly different. However, there is cross-pollination between them, so when Silverlight comes without things like WrapPanel, someone wrote their own implementation in Silverlight (and was eventually added to the Silverlight Toolkit).

Do not expect copy and paste from WPF unless it is trivial code. Things like data binding are slightly different in Silverlight (for example: lack of binding to other elements). In most cases there are workarounds.

+4
source share

Take a look at this article , it talks about the many things you need to do for a port from SL to WPF. This article also has a link to Scott Goode's blog on the subject; however, this article talks about some of the differences not mentioned on Gu's blog.

+4
source share

Silverlight is designed to be a compatible subset of WPF (at least where it makes sense). This means that porting your application from Silverlight to WPF should be relatively straightforward. Going the other direction (WPF → Silverlight) is likely to be significantly more complicated.

The example you give in your question illustrates this point; the page class that is used in the default WPF project template is not in Silverlight. But the UserControl class exists in both. This way you can copy and paste xaml and code from a Silverlight application, which does not cause problems with UserControl in your WPF application.

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

+1
source share

All Articles