bobby's blog

randomly specific...


News

My Stats

  • Posts - 15
  • Comments - 49
  • Trackbacks - 0

Twitter












Recent Comments


Recent Posts


Archives


Post Categories


Image Galleries


My Links


User Groups



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