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!

Download the source code and have a look for yourself…. Compare the 2 versions and see how much better we WPF developers can today use MVVM 🙂