Can Of Code

Tag Archives: MVVM

Understanding MVVM using MVVM Light

I had come across MVVM a number of times in my WPF travels but only in the form of the letters on a screen, so like any budding software engineer i decided to investigate.

WTF IS MVVM?

This question is where i started and it was a question i struggled with,  It seams that most people who write about MVVM are unable to explaining it such a manor that simple folk like myself can understand. Here is what i understood after reading a number of explanations.

Its a method of designing software so that you can easily separate the layout from the data. Separating the data makes testing easier and allows you to see test data when designing your layout in tools like Expression Blend.

The letters do actually mean something:

Description of View, View-Model and Model of MVVM

M = Model

This refers to your classes that define your OO business objects, for example your Customer class with the customers properties like customer name etc. Nothing new here!

V = View

The view is very much your XAML code and that’s it! The view is your Window. each new window is a view.

VM = View Model

The view model is the bit that is perhaps more confusing. The view model loads your data using your model and then using bindings lets your view use that data for the user interface. The View Model is where your load in your data from the database and load it into BO defined in your Model.

 

The order of the letters of MVVM i find disjointed. if it was up to me (for many reasons its not) i believe it should be View View-Model Model or VVMM, doesn’t have the same ring does it?

That’s Wonderful dear, But where on earth do i start?

Well word on the street has it that, doing things MVVM style adds more code to the proceedings, but.. before you hit the back button, someone has already done the hard work for you! This comes in the form of MVVM Light. You can download MVVM Light as an installer (Install MVVM Light). MVVM Light consists of a small framework that just takes out some of the hard graft, so i am told. Once installed all you have to do is create a new project using one of the freshly installed templates within VS2010.

This MVVM Light, What do i do with it?

To get started with MVVM Light,  i recommend that you go to the MVVM Light site which have a few tutorials to get you going. The most useful i found was the video explaining MVVM and MVVM Light and also a nice simple tutorial can be found here.

I’m still getting used to MVVM Light so i shall likely have some more posts on it soon.

Posted in Software, WPF | Tagged , , | 1 Comment