<Download Code> Click here to download a WPF version of this Digg client sample. </Download Code>
Creating a Digg Desktop Application Using WPF
Our goal with this last tutorial is a little different than the previous seven tutorials. We actually aren't going to be running code in Silverlight with this tutorial - instead we will be using WPF and .NET 3.5. We'll be taking the existing Digg application code we've written to run inside Silverlight in the browser, and re-use it to also run as a Windows desktop application.
Silverlight ships with a compatible API subset of what is in the full version of the .NET Framework. One goal with this is to enable developers to learn a common programming model and tool-set and be able to re-use skills, code and content across RIA web applications, rich Windows desktop applications, and Office solutions.
Below are the steps I took to re-use our existing Digg Silverlight application code (which runs in the browser) to build a Windows desktop application version (which runs outside the browser).
Step 1: Create a New WPF Desktop Application
We'll start by creating a new WPF Desktop Application using VS 2008. We'll name it "DiggDesktopSample":
This will create a project inside VS with two files - an App.xaml, and a Window.xaml:
Note that this project structure is very similar to the Silverlight one we created in Tutorial 1 of this series (which had an App.xaml and a Page.xaml file).
Step 2) Copy Existing Digg Application Code into the WPF Application
We'll copy/paste our existing DiggApplication Silverlight code into our new DiggDesktopSample Windows project:
Currently in Beta1 this copy/paste effort is a manual step - we will eventually have a more automated way to move the code between project types.
Step 3) Fix Up a Few Issues
I had to make two changes to get our existing Digg sample code to compile:
1) The Silverlight Beta1 XAML schema xmlns: URL is different than the full WPF desktop version. I needed to tweak the XAML files I copied into the new project to point to the full WPF schema. This is something we are looking to improve before we ship.
2) I had to change the <WaterMarkTextBox> control to <TextBox> and change the <HyperlinkButton> control to be a <TextBlock>. These are two controls that are new in Silverlight Beta1 that aren't in the full WPF yet (we will add them in the future though). I did not have to change any of the code that worked with these controls, though, nor my network, LINQ to XML, nor databinding code.
Once I made these small tweaks the project compiled clean.