ViewModel Pattern for Silverlight – Options for Hooking a View to its Model

In the ViewModel, aka the MVVM pattern, a view such as a UserControl is bound to its associated view model. The view model manages state exposed as observable properties, operations exposed as methods and raises notifications via events. An interesting question is how a View should specify its view model, and how a view model instance should be created. Like everything else in the ViewModel pattern, this topic is no different. There are different strategies, with pros and cons, and different people have different opinions.

In this post, I’ll describe a couple of options, and hope to collect some feedback as well as ideas on alternatives. Part of my goal here is to improve what is supported in Silverlight.FX out-of-the-box. The other goal is to find what resonates, and see if I can collect input on suggestions I’d like to make for future ViewModel support in Blend/Cider – so any thoughts you share will certainly help. Looking forward to hearing them…

My general criteria for evaluating each approach is the following:

  1. It should be possible to create the view model through an IoC container, so its dependencies (properties, or constructor arguments) should be satisfiable. In other words, its likely a view model can’t be instantiated directly in XAML… at least not in the subset of XAML supported by Silverlight today.
  2. The mechanism should not interfere with designability either in Blend.
  3. Furthermore, the mechanism should even lend itself to designability. For example, the data-binding picker should allow binding to properties on the view model.

[Full post continued here…]