Geeks With Blogs

  • bmdiaz I like getting new toys to play with... it's like Christmas all over again! #geekshavemorefun about 1153 days ago
  • bmdiaz @Buster_ESPN 3.,,,?))(665555568bujujjjjhjjjjjjiiooiiiiiiiuiuii nnbb about 1254 days ago
  • bmdiaz @gblock I think Visual Studio also stores alot of crap in there too... about 1327 days ago
  • bmdiaz I'm really diggin #android development! My java rust is finally starting to fall off... about 1485 days ago

bobby's blog randomly specific...

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



2. MainViewModel.cs


3. ViewModelLocator.cs



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!


Additional Resources

Posted on Wednesday, March 31, 2010 10:45 AM Silverlight , MVVM | Back to top

Comments on this post: KISS and Tell - MVVM and the ViewModelLocator

# re: KISS and Tell - MVVM and the ViewModelLocator
Requesting Gravatar...
This is an interesting approach, the only downside being that the view is not discovered by waking the stack trace when in design time. It's been a while since you posted this snippet. Have you taken the ViewModelLocator dilemma any further..
Left by Ralph Shillington on Dec 26, 2010 4:13 PM

# re: KISS and Tell - MVVM and the ViewModelLocator
Requesting Gravatar...
This is the article gives the light in which we can observe the reality. this is very nice one and gives indepth information. thanks soo much for this nice article.
Left by Investment Options on Jun 03, 2011 4:33 AM

# re: KISS and Tell - MVVM and the ViewModelLocator
Requesting Gravatar...
Hello Bobby,
i was interested in your conventional based viewmodellocator. But in production code i think that you cant use stacktrace as you did. Methods like Initialize component are not in stack trace. They are inlined because of optimization and whole stacktrace is completely different (there are no names of some methods etc.) from one when app is run with VS. But thx for your post it was great inspiration for my own implementation.
Left by Radek on Jun 16, 2011 3:14 PM

Your comment:
 (will show your gravatar)

Copyright © Bobby Diaz | Powered by: | Join free