Single source code base for Silverlight and WPF solutions


At Mix08, several people asked me about the possibility of creating a single source base for both WPF and Silverlight.  The scenario folks had in mind was to provide a reach solution with Silverlight that hits *ALL* possible users while also offering a really rich solutions for some users on full WPF (.NET Framework 3.0 or 3.5). 

This is a clear benefit of the Microsoft Ux platform.. We have worked hard to get a smooth continuum between WPF and Silverlight… Basically if it works in Silverlight you should be pretty sure it will work on WPF. 

I was chatting David Anson (one of the developers of the Silverlight 2 controls) and he mentioned that the shipping versions of ListBox and ScrollViewer were written this way!   That is right, to test out the continuum message, David built ListBox and ScrollViewer for Silverlight in such a way that the run (and past unit tests) on both WPF and Silverlight.  

Now, in and of itself, this is not all that interesting, because WPF already has a ListBox and ScrollViewer, but it does serve as a nice test case to demonstrate how you can build controls and applications that work on both Silverlight and WPF. 

image

Because we shipped the source and unit tests for the Silverlight controls, you can check this out yourself

In addition, David did a nice blog detailing the work he did and why and posted the test project you can try out as well. 

On a related note, be sure to check out the final step of ScottGu’s Silverlight 2 tutorial...  Notice how easy it is for him to make a WPF application out of it.

Comments (11)

  1. SomeOne says:

    Not if you use the DataGrid in SilverLight where is that in WPF? Or the WatermarkTextBox?

    Yes only if Silverlight is a TRUE subset of .NET. I understand that SL 2.0 is beta and beta can have things that are not prime time. But when SL 2.0 goes live are we going to have controls in WPF that are not but are in SL 2.0?

  2. Not if you use e.Handled to stop propagation of a routed event…

  3. Steve says:

    Where are the controls at ?

    Or is it just a movie player and gradient builder ?

  4. BradA says:

    >> Not if you use the DataGrid in SilverLight where >> is that in WPF? Or the WatermarkTextBox?

    Good call… we are missing some controls in WPF right now… we are working on addressing that… look for more information on that soon.

  5. BradA says:

    >> Where are the controls at ?

    The current set of controls are in the Silverlight 2 SDK.. more information here:

    http://blogs.msdn.com/brada/archive/2008/03/05/silverlight-2-controls.aspx

  6. I noticed that Scott mentioned in his "fix up the xmlns" that the namespace difference might be cleared up. If that is done, any hope for creating Assemblies that can compile both Silverlight and full .NET assemblies from one codebase. I’m currently tricking VS.NET into letting me share classes between assemblies (follow the link above for the how), but that method would be seriously tedious for sharing Controls between Silverlight and WPF.

  7. divil5000@hotmail.com says:

    This is so far from reality it’s just not funny. Maybe in beta 2 this will be possible, but there are so many fundamental things lacking in SLB1 that people are just used to in WPF that it isn’t.

    Even down to the way things are defined in XAML – where’s {x:Type} ? How do we have a generic.xaml for a control library for compiles for both platforms? You simply cannot.

  8. Sharepoint SharePoint Slipstreams recently announced [Via: slennon ] WPF Usability Design For Forms:…

  9. Infragistics is one of the major ISVs developing controls for Microsoft platforms. I favorably reviewed their NetAdvantage controls for ASP.NET for InfoWorld in 2006. They have also released controls for Windows Forms and Windows Presentation Framework

  10. Calvin Guo says:

    This is actually not as convenient as it sounds. Suppose I have a project with 250 c# files in it, which compiles fine in silverlight. Now I want to compile it in WPF, I have to open the project file to change all the references, and recompile.

    If this sounds tedious, it gets worse when maintain this project, add a new file, remove a file … etc. Keep the 2 project files in sync is a pain in neck.

    Any easier ways?