views:

5573

answers:

5

Is it possible to convert an existing WPF Application to SilverLight automatically/with minimal effort?

+2  A: 

No. Silverlight runs in its own cut-down version of the CLR. It also is WPF-like, not WPF. You'll have to do a fair amount of work to convert it.

Will
+5  A: 

Not really. I have found some articles regarding the multi-targeting option for WPF and Silverlight at the same time. At this moment, if you are not using PRISM, it is quite a challenge to target both of them, fortunately achievable.

What do you need to have in mind is that Silverlight uses a smaller (thus more limited) library than WPF.

In response to the comments: Actually, there is already support for silverlight in PRISM (v2). The idea of PRISM is to provide guidance to developing applications not only using WPF but using Silverlight also - Prism V2 formally was known as Composite Application Guidance for WPF and Silverlight. By using PRISM for silverlight capabilities, it would give you the warranty that your code would work on both platforms with minimal changes, if none (except maybe the different project types for visual studio).

But of course, if you already started developing your application, you would need to change your code to use PRISM.

Bogdan Maxim
Thanks for pointing out PRISM. I'll take a closer look on that.
Salamander2007
Prism is guidance for developing composite applications using WPF. They plan on having guidance/libraries for Silverlight at some point ... however, the point is ... that PRISM _doesn't_ necessarily help you write a WPF application that is easily converted to a Silverlight application.
cplotts
I don't see why Prism has anything to do with porting Silverlight to WPF. Prism is a library and some helper classes - You can just as easily port plain Silverlight code and XAML to WPF without it.
Jonas Follesø
+5  A: 

Will and Bogdan's answers are correct. The keyword here is "minimal". Rob Eisenberg has a list of differences here (though this was pre-RTW).

List of Differences in WPF & Silverlight

bennage
Excellent Google optimization of that link. ;) But the the links are NOFOLLOWed. Which, BTW, maybe they shouldn't be, after a certain rep level. Or better yet, after an Answer reaches a certain score, like 8 or s0).
kcrumley
+7  A: 

I would argue that you CAN port Silverlight to WPF with minimal effort. I spent 2 hours porting and application I spent 3 weeks writing. I would argue that those 2 hours spent would categorize as minimal effort.

Sure, you need to create a new project, add the files to the new project and tweak them.

Since Silverlight is a subset of WPF its allot easier to go from Silverlight to WPF than the other way around.

For business logic and non-UI code your code should port almost straight across. I had some minor issues around authentication, as Silverlight 2 will pick up any authentication information in the browser, while in WPF you have to role your own login screen and manage cookies etc.

For the XAML it will port straight across if you don't style your controls. If you style your controls the use of the Visual State Manager, currently missing in WPF, will make things a little trickier. You can either re-style your controls in WPF using Triggers, or you can use the VSM implementation for WPF done by John Gossman. Microsoft have announced that they will add the VSM to WPF to make the two frameworks more compatible.

The perhaps most important reuse tough, is skills and experience. Since the two platforms are so similar you will be able to reuse all your skills in WPF.

I recently did a blog post about the Dive Log sample application and how I ported it from Silverlight 2 to WPF. Might give you some idea of the process.

Jonas Follesø
A: 

Here is a thread about this: http://silverlight.net/forums/t/3898.aspx