WPF and MVVM tutorial 01, Introduction.

With Microsoft WPF technology, a new pattern is born and is going to be called MVVM (Model View ViewModel). This pattern is an hybrid from the old MVC and the old MVP patterns. Why a new pattern for the presentation?

  1. First of all WPF technology is giving us a kind of technology that can completely change the approach to design and code the UI. With the VMMV we can completely design an agnostic UI that doesn’t know the Model we are going to pass to it.
  2. Recycle, I will show you in this tutorial how to simply convert a WPF application into a Silverlight app.
  3. Better delegation and better design for a real n-tier application. In this example we will use LinqToSQL and WPF to build a complete n-tier application with the VMMV.
  4. Something that I do not like, TESTING THE UI!! Yes we can test the UI with WPF and VMMV combination.
  5. Abstractation. Now the view can be really abstract and you can use just a generic.xaml file and then give a style template to your model.

This is the schema (in my opinion) on how it should work an application with WPF and the VMMV implementation:

image

  • MODEL: anyone that has already worked on an n-tier application knows what it is. The model is the group of entities that will be exposed.
  • VIEW: the view is the graphical code XAML used to generate the UI, nothing more then that.
  • VIEWMODEL: the model for the view … or … the view for the model?! Anyway is a model of the view.

Before starting this tutorial I suggest you to download:

The next tutorial will show you how to create a simple DAL layer with LinQtoSQL and how we can implement the Unit of Work pattern to build a simple but solid data layer for our application.

You can also download the Visual Studio template here.

Tags: