Thursday, March 24, 2011 11:29 AM
Thursday, March 24, 2011 2:04 PM
This is quite a complex issue. The problem is that you want to validate in your model, but represent the errors via the view model. What you should do in your view model is check for property changes. When a property on the view model changes, you should set it on the model to make it cause an error. Then, you will have to read the errors (via IDataErrorInfo) and set the same error on the view model.
Sounds easy, but this is very complex. For example, what if the view model is canceled. Then, you will need to restore the original values on the model as well.
In Catel, we have thought of this issue and handled ViewModelToModel mappings. This way, errors and values are directly passed from the view model to the model and back on changes. This way, you can still handle the validation in the model and pass it through to your view model (and eventually the view) via simple attributes.
This article explains all about the attributes in Catel and how they should be used. You can also consider writing this yourself.
Geert van Horrik - CatenaLogic
Visit my blog: http://blog.catenalogic.com
Looking for a free open-source MVVM framework for WPF and Silverlight? Check out Catel!
- Marked As Answer by Bob_BaoMVP, Moderator Thursday, March 31, 2011 7:56 PM