Article revisited: MVVM + M (implementing a Fly Weight TreeView)
Ages ago I wrote an article to introduce an idea that I had for the Mediator pattern to work with MVVM (at that time MVVM was still in the being of its age so I didn’t even call it View Model I called it Controller).
Today I was preparing for a Demo that I will be doing in Poland and I thought to revisit this article and refactor it with the new methods that I discovered over the last year.
What’s new in the new and exciting in the new version.
>> Well for starters I am using a new and improved version of the Mediator. The new version of the Mediator API is much more user friendly. It support Generics and it also eliminates the need to have interfaces implemented for you ViewModel. Instead of implementing an interface and have a switch for the message type now you simple register a message to an Action delegate. The Action delegate can be of a generic type so that you don’t even have to cast the argument. You can read more on this over here.
>> This version also uses Service Locator and the concept of ViewModel Loaders that I introduced in this article.
>> It also uses attached behaviours for the TreeView instead of a ViewModel registering to routed events of the treeview through the EventManager. This is much better! Event Manager registration of event inside a ViewModel can be very dangerous and also makes the ViewModel dirty with references to UI elements. Yet at that time it was an approach that I thought was best, as I said those days were just when View Model concept was emerging…
It’s amazing what I have learnt in the last year and how much MVVM evolved!





Doesn’t it feel great to see improvements in your coding techniques and thought processes?
Great job!
It does and that’s why I posted this
hi, the .zip file is missing the MVVMHelper
Thanks for pointing it out… I updated the link this should include MMVM Helper… Thanks again
Things have indeed moved forward rapidly. Great job Marlon!
Hello
I really liked the idea of using your Mediator with the MVVM pattern, but Im really into silverlight, so i tried it out in silvelight 3.
But I ran into a one problem…when calling CreateDelegate(….) in the method CreateAction()
I get an MethodAccessException…and it is an internal method call which emits the exception.
I just wandered if you have thought about implementing the Mediator for Silvelight? Do you have an idea why this Exception occurs in Silverlight? Trust?
I know that the mediator was made for WPF but did you try it out for Silvelight?
I like your ideas by the way!
Best Regards
Bård Pettersen
I beleive this version will fix your issue
http://marlongrech.wordpress.com/2009/04/16/mediator-v2-for-mvvm-wpf-and-silverlight-applications/
Hi i really like your blog, i hope to see more great soon