views:

129

answers:

4

Is it possible to develop against Silverlight and WPF using the same source code? Maybe using some #define blocks where it is necessary.

+2  A: 

Theoretically it should be doable. It's not a big problem for the code. However, you'll have to be very careful with XAML and use only the intersecting subset of WPF and SL (1), as there's no #if/#endif for XAML.

(1) Contrary to the common belief, SL is not a proper subset of WPF. It has some features that WPF does not have, though these are being worked on.

Franci Penov
+1  A: 

Incidentally, PRISM (the composite application block from patterns and practices) now supports Silverlight and there's a C9 video with a quick sample on using code in both WPF and Silverlight.

I think if you stick to MV-V-VM (or something along those lines) then a lot of your backend code will be reusable, but the XAML itself might need to be forked if you want a full on "rich" experience, unless you are willing to use the VSM beta for WPF.

Steven Robbins
+1  A: 

I have no experience on that but I have used a component that targets both WPF and Silverlight environment with the same code (there are only few differences).

The component is Chart from Visifire and it's Open Source

Maybe you can take a look into it

marco.ragogna
A: 

You can use Visual Studio file linking to include classes from WPF projects in Silverlight - but only if they don't do any UI or XAML based stuff (as this is where you will usually find inconsistencies between the two)...

So keep it to business logic etc.