Validation using IDataErrorInfo (if that is what you are using) will happen on the object that is associated with the view.
so if you
<TextBox Text="{Binding Name}" />
it will be in the ViewModel. However, if you expose the model as a property in the presentation model, validation will occur in your data model.
<TextBox Text="{Binding Model.Name}" />
With the first choice, you can bind to the properties of the view model and route to the data model where it contains the actual check, and then just implement IDataErrorInfo in the view model and redirect the check to the model
ViewModel:
public string this[string propname] { get { return _model[propname]; } }
This is only useful if you have really set the required model properties to verify operation.
ViewModel:
public string SomeProperty { get { reutrn _model.SomeProperty; } set { _model.OtherProperty = value; RaisePropertyChanged("SomeProperty"); } }
However, I prefer the second binding option, because the problem is that it is not very DRY, therefore I almost always expose the DataModel as a property in the view model (since this is responsible for the data) and leave the ViewModel controls the model for the view, which is more related to the interaction user interface with data.
In very complex scenarios, it might be better to separate validation from the view model and the view model and use both the view model and the data model.
aqwert
source share