I have the following question:
I'm using the INotifyDataErrorInfo validation for validating my models. Now i have the requirement to validate my model on "entity-level" so the whole state of the model object should be validated.
That's all working and the validation rules return an error but how can I now ensure that a Validation.Error event is raised for my model so I can catch it at the MainWindow-Level to display an error message?
For my Properties I write the following in xaml so a Validation.Error event is raised:
<TextBox Text="{Binding PropertyName, ValidatesOnNotifyDataErrors=True, NotifyOnValidationError=True}" />
I would be very happy if someone can provide a working example for me, Thanks!
@ninja hedgehog: Yeah I know that but the problem was to get an event for model-level errors too.
But now I've found a solution for the problem.
If you want to have Validation.Error events for the whole Model then you have to make a binding of for example DataContext on the parent control. The following example will explain what I mean:
So the Binding for the DataContext on the Grid now listens to the INotifyDataErrorInfo.ErrorsChanged Event of the Model and if there is an error the Validation.Error RoutedEvent get's raised for the whole model.