views:

18414

answers:

10

I've read a number of good articles about the Model-View-ViewModel pattern and my team intends to implement this pattern in the latest version of our app. I still don't quite get ALL the bits that go together to make this work. I'd like to find a good example of this pattern that I can work through. Something on a small scale, much like Jason Dolinger does in his video here, but I'd like something that I can work through on my own at a slower pace.

Thanks in advance for your help.

+11  A: 

Basically a ViewModel is a wrapper around model. Now that might not be very helpful yet :-) Think of the model as the data your application works with, say a person. Now a person has a birthday and you might want to have a form to enter the person's birthday. Suppose we are just using a simple TextBox the date shows up something like 01-02-2009 12:00:00AM. For starters we don't want the time part and we also might not be to happy about the 01-02-2009 part as this depends on your locale settings.

So here the ViewModel comes im. It wraps the Person class and exposed the date as three integer values, year, month and day. In the property set it tries to build a date from the different values and displays any errors that might occur.

So simply said a ViewModel is a Model wrapper specifically geared towards a particular view (display). It eliminates most IValueConvertors at the same time.

Josh Smith has a nice explanation here: http://joshsmithonwpf.wordpress.com/2008/11/14/using-a-viewmodel-to-provide-meaningful-validation-error-messages and a big discussion here: http://groups.google.com/group/wpf-disciples/browse_thread/thread/3fe270cd107f184f?pli=1

Maurice
+1  A: 

Nikhil Kothari has a post about how to use that pattern with his Silverlight.FX library. Check it out here: http://www.nikhilk.net/ViewModel-Pattern-DLR.aspx

Guillaume Gros
+4  A: 

Take a look at this for basic intro... http://blog.jeffhandley.com/archive/2008/10/27/helloworld.viewmodel.aspx

When you're ready to incorporate into your architecture, I've found Jonas Follesoe's blog contains some great best practices... http://jonas.follesoe.no/TechEd2008NdashSilverlight2ForDevelopers.aspx

David Burela did a nice synopsis on Joans' principles... http://davidburela.wordpress.com/2008/10/19/silverlight-mvvm-dependency-injection/

arch
A: 

Josh Smith just published an E-Book titled Advanced MVVM

Mike B
+3  A: 

You may have already found the answer you liked but from what i see this is the best BEGINNER MVVM video i have seen yet. Breaks it down for me like i was 3 years old... This is with Tim Heuer and Craig Shoemaker http://community.infragistics.com/pixel8/media/p/91949.aspx

Rico
+1 - by far the best of the ones listed IMHO
Tom
Thought this may help someone as well. This is the easiest MOst Simple MVVM Project i have found. Dan Explains it Like no other... http://weblogs.asp.net/dwahlin/archive/2009/12/08/getting-started-with-the-mvvm-pattern-in-silverlight-applications.aspx
Rico
+1  A: 

There is also:

Silverlight MVVM: An (Overly) Simplified Explanation

Michael Washington
+1  A: 

Take a look at this: It gave me enough confidence and example to implement a simple internal app: http://wildermuth.com/

SiKo
+1  A: 

Prism 4.0 now includes documentation for creating MVVM applications. This is targeted for using the Prism libraries but the concepts work for the MVVM pattern in general.

http://compositewpf.codeplex.com/releases

Andy May
A: 

I have gone through many recently, the two that stand out are:

Dan Wahlin's (LIDNUG):

http://www.lidnug.org/Archives.aspx

John Papa's (PDC 2010):

http://player.microsoftpdc.com/Session/76864d75-b4da-4858-aac7-786c5f28e344

Tom
+1  A: 

did a couple of them a while back. One for MVVM with WPF and then one on Command Binding with WPF and Silverlight. Feel free to use them if you like.

MVVM Example

tsells