The first step is to create an entity class, the Model. This class stores only data. To support binding and data validation in WPF, it also implements the IDataErrorInfo interface. Entity classes can be generated by object-relational mapping (ORM) tools like NHibernate or Microsoft Entity Framework. Or you can implement them yourself using e.g. Active Record, Data Mapper, Row Data Gateway, or Table Data Gateway patterns. The entity class don’t have to implement INotifyPropertyChanged interface, this functionality will be provided by the ViewModel.
Next you create the ViewModel. This class will be the link between the Model and the View – between the data and the user interface elements. It will store and update the Model data, and it will transform the data to be displayed on the user interface. ViewModel has the same properties as the Model (or a subset of it). ViewModel can provide calculated fields to be displayed as well. All properties signal their change, so ViewModel implements INotifyProperyChanged interface and fires the appropriate event in case of property value change.
ViewModel can react on commands. It can save its content into the database (using ORM functionality or something like that. ) While you should implement every single commands if you implemented ICommand on its own, you can introduce the RelayCommand class.
RelayCommand simplifies the ICommand implementation to the following few lines:
public ICommand SaveCommand
if(_saveCommand == null)
_saveCommand = new RelayCommand(
param => Save(),
param => CanSave);
View is simply a user interface component, like a DataGrid. You can bind your ViewModel to the view and the view will update itself in case of data modification (or can update data in case of two-way binding). You can bind a control to the command of ViewModel and the control will enable/disable itself if the command behind the control cannot be executed (e.g. you can’t save the data because the model data contains errors).
MVVM pattern is complicated at first sight and you will have to create much more complicated architecture and classes, but it worths to understand and implement.