Search code examples
wpfmvvmmvp

My interpretation of the MVVM-concept in WPF (In relation to presenters)


Is this a correct interpretation of the MVVM-concept?

  • DataTemplates -> View
  • DependencyObject (Controls, ListView etc) -> ViewModel
  • DataContext -> Model

If I were to create my own ViewModel, it would replace the actual controls and need explicit templating?

The word 'Model' in ViewModel is not reffering to the actual Model (such as in DomainModel)?

To the model I add Presenters as well, which I see as utility-classes to elevate and expose properties etc to the view. Can you say that a ViewModel is a top-down representation (a model of a view) and that a Presenter is more of a ModelView, a bottom-up representation (a view of a model)?

In that case I would have to modify the above to this:

  • ...
  • DataContext -> Presenter
  • Presenter -> Model

And I wouldn't generally derive from DependencyObject to create my custom presentation-wrappers, but only to create my custom generic models of views such as controls rather then views of my model?


Solution

  • Usually MVVM is meant to be interpreted this way:

    View -> Controls, DataTemplates etc.
    Model -> Your actual data model (database, or whatever)
    ViewModel -> Exposes properties and commands that the View can use for DataBinding

    That means, your View has the ViewModel as a DataContext, the ViewModel's properties reflect the Model's data, and the ViewModel's Commands operate on the Model. In simple cases, Model and ViewModel are sometimes the same.

    An overview can be found here: http://blogs.msdn.com/b/johngossman/archive/2005/10/08/478683.aspx
    You can also find quite a few examples on building an MVVM Application if you look for it.