KISS and Tell - MVVM and the ViewModelLocator

Posted by Bobby Diaz on Geeks with Blogs See other posts from Geeks with Blogs or by Bobby Diaz
Published on Wed, 31 Mar 2010 08:45:34 GMT Indexed on 2010/03/31 16:03 UTC
Read the original article Hit count: 536

Filed under:

A popular topic that comes up when talking about MVVM is the use of a ViewModelLocator and the many different ways one can be implemented.  Rather than getting into the pros and cons on when or why you should use it, I decided I would just post my version of a simple ViewModelLocator and let those who like it use it, and those who don’t, well you know…  :)

First, a disclaimer.  I have not used this code in a production application, it is just something I was tossing around while reading others’ posts on the subject.

1. MainView.xaml

image

 

2. MainViewModel.cs

image


3. ViewModelLocator.cs

image

 

I have a codepaste of the ViewModelLocator.cs file if you are interested but don’t feel like re-typing the 50 lines of code!

Enjoy!

Additional Resources

© Geeks with Blogs or respective owner