Microsoft’s unified client application development stack is so awesome. If you are equipped with the knowledge of developing Client applications leveraging XAML and MVVM, you should be able to build applications for multiple devices, including Windows Phone 7, Silverlight, WPF and Microsoft Surface. And to a great extent, you can re-use code across these, if you wish to.
A Quick Introduction
In short, we will see how we are re-using most portions of the source code (including the View Model) across WP7, Silverlight, WPF and Surface, to build a simple RSS Reader. During my Virtual tech days demo, I gave a session on building an Rss reader by sharing the code across WP7, Silverlight, WPF and Surface. The screen cast is now available for download, and you may watch it here. The video also explains the basics of XAML, MVVM etc.
What we are building?
To begin with, I’m using Microsoft Visual Studio 2010, with Silverlight developer tools, Windows Phone 7 tools and Microsoft Surface SDK for touch devices installed. We’ll be building an RSS reader, for all the above devices, and these are the screen shots of the final applications.
In Surface Simulator:
In Browser (Silverlight):
In Desktop (WPF):
In Windows Phone 7:
As you may see in the above demo, almost 80% of the code is shared via multi targeting. The classes we share include
- RssReaderViewModel – Which is our actual view model.
- RssEntry – The model element that actually holds a element.
- RssReader – Contains methods for fetching the RSS feed from a remote server.
- AsyncDelegateCommand – My own asynchronous version of delegate command.
In all the projects, you may see a ‘Shared’ folder, that has the links to the shared files in the RssReader.Common project. The views are different per device, but the view model, the feed fetching logic etc remain the same. See the Solution Explorer.
The Source Code
Explore the source code here in Codeplex. It is a quick demo I’ve put together, so you should add stuff like proxy support for the web client if you are going to test this behind a proxy.