Search code examples
wpfmodel-view-controllermvvmmvp

wpf mvvm confusion


as per my understanding about mvvm is.

there is a model (entity class that also implement inotify...), view (xaml code) and some class as vm (kind of controller which normally inherit icommand) to let us make events/commands to be generated on specific event...

m just wondering about difference between viewmodel class and xaml's code behind class... why don't we simply consider and enhance code behind...

no considerable reason is in my mind to justify this...

or kindly write somethng with example to clear mvvm... and why mvc or mvp is hell for wpf app????


Solution

  • The Model does not implement INotifyPropertyChanged, the ViewModel does. The actual WPF view data-binds to the ViewModel. There is now a lot of documentation online for this.

    http://msdn.microsoft.com/en-us/magazine/dd419663.aspx

    MVVM is identical to Fowler's Presentation Model, in that both patterns feature an abstraction of a View, which contains a View's state and behavior.

    http://blogs.msdn.com/johngossman/archive/2005/10/08/478683.aspx

    In practice however, only a small subset of application UI can be data bound directly to the Model, especially if the Model is a pre-existing class or data schema over which the application developer has no control. The Model is very likely to have a data types that cannot be mapped directly to controls. The UI may want to perform complex operations that must be implemented in code which doesn't make sense in our strict definition of the View but are too specific to be included in the Model (or didn't come with the pre-existing model). Finally we need a place to put view state such as selection or modes. The ViewModel is responsible for these tasks. The term means "Model of a View", and can be thought of as abstraction of the view, but it also provides a specialization of the Model that the View can use for data-binding. In this latter role the ViewModel contains data-transformers that convert Model types into View types, and it contains Commands the View can use to interact with the Model.

    MVVM is associated with WPF because WPF's data binding mechanism when combined with this pattern makes testable GUIs a breeze.