Click here to Skip to main content
12,824,299 members (41,562 online)
Click here to Skip to main content
Add your own
alternative version


36 bookmarked
Posted 21 May 2009

Moving from Windows Applications to WPF

, 8 Jun 2009 CPOL
Rate this:
Please Sign up or sign in to vote.
Thinking cap for starting WPF


I must say, WPF is a programming language which has some of the difficult syntax to start with. I was wondering what those bindings, routings are doing in the first place? All Windows programmers who are used to the layered (tiered) architecture will be wondering how to cope with these new concepts.

But then if you start learning WPF in conjunction with MVVM design pattern, it will be a fun. It segregates the business layer, data layer from the View. Yes, this is what the basic three tier architecture concept is all about!!! Looking at MVVM, one could easily say that it is tailor made for WPF.

Let’s try to move from Windows .NET 2.0 to WPF programming. We will first see a simple Employee management system developed using .NET 2.0. We will then try to develop the same using WPF with MVVM design pattern.

Visiting 3 Tiered Architecture

When developing professional software, we always want to keep the UI separated from the business component and the data. 


We usually hold a business object behind every UI which mediates between UI and the model. The business objects strongly follow the “patterns and practices” to make the application scalable. The attached source code contains an example demonstrating a simple Windows application. It is having a Simple Windows Form with two ComboBoxes, one to select Employer and the other to select employee. Once you select an employee name, you can view his/her details.

On the WPF Way

Now get back to WPF. We have UI blessed with bindings. Then we always have those data objects which keep the editable data in memory (in memory representation of database). Now we can bind the data with UI. Bindings allow us to update data in both ways. We can update UI from data or data from UI.


Let's convert the above .NET 2.0 application to WPF. We can reuse the existing data layer. So we have the data. We will develop WPF application to display the information. We will follow the MVVM design pattern. We have XAML as View. We have the data layer as Model. It's time to pass this model information to View. We will design a layer (ViewModel) which will encapsulate model from View. The ViewModel will act as DataContext to View. We will use DataContext in XAML binding. So when you update the ViewModel from View (because of binding), view model will internally update the Model.

So let’s pull some tricks from the MVVM (or Josh Smith’s brainchild) to elicit WPF programming. 


The above diagram depicts the details about how WPF applications can develop using MVVM design pattern. This article talks about developing a WPF application using MVVM, so let's remember a few guidelines for MVVM.

DeFacto for MVVM

  1. No code behind of XAML - absolutely clean view design
  2. View model should be passed as DataContext to UI View
  3. View model and Model should not access any UI/View component, object
  4. View model should inherit INotifyPropertyChanged. This is required to make ViewModel as Binding source
  5. View model should encapsulate model - This hides the intricacy of data storage from View

You Can Also Refer To The Links Below to Enhance Your WPF Skills


  • 21st May, 2009: Initial post
  • 22nd May, 2009: Minor updates
  • 6th June, 2009: Included an example to demonstrate .NET 2.0 application and its WPF equivalent


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer
Australia Australia
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralWhere is the code Pin
Arfan Baig18-Mar-10 21:15
memberArfan Baig18-Mar-10 21:15 
GeneralThanks .. Good job done !! Pin
Arindam Tewary2-Oct-09 11:55
memberArindam Tewary2-Oct-09 11:55 
GeneralRe: Thanks .. Good job done !! Pin
RakeshGunijan2-Oct-09 18:41
memberRakeshGunijan2-Oct-09 18:41 
General[My vote of 2] need more work Pin
Donsw14-Jun-09 12:09
memberDonsw14-Jun-09 12:09 
GeneralMy vote of 1 Pin
Jammer8-Jun-09 12:41
memberJammer8-Jun-09 12:41 
GeneralMy vote of 1 Pin
ameetj858-Jun-09 8:12
memberameetj858-Jun-09 8:12 
GeneralMy vote of 1 Pin
DpMozz8-Jun-09 6:17
memberDpMozz8-Jun-09 6:17 
GeneralMy vote of 1 Pin
d1241222-Jun-09 1:28
memberd1241222-Jun-09 1:28 
GeneralMy vote of 1 Pin
wegenerb25-May-09 6:42
memberwegenerb25-May-09 6:42 
AnswerRe: My vote of 1 Pin
RakeshGunijan25-May-09 18:16
memberRakeshGunijan25-May-09 18:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170308.1 | Last Updated 8 Jun 2009
Article Copyright 2009 by User-Rock
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid