There is only 3 things inside of INotifyDataErrorInfo:
HasErrors
: a read-only boolean property which tells if the object as a whole have any validation errors;
GetErrors
: a method which returns validation errors for a given property;
ErrorsChanged
: an event which must be raised when new errors – or the lacks of errors – is detected. You have to raise this event for each property.
In the demo project I create a form which display the properties of an object named ‘Person’
. Here is how the validation with INotifyDataErrorInfo is enabled in the Binding:
<TextBox Text="{Binding Name,Mode=TwoWay,ValidatesOnNotifyDataErrors=True}"/>
We have to set the ValidatesOnNotifyDataErrors
property to true
.
The binding will then register itself for the ErrorsChanged event of the binded Person. Eeach time this event is raised for the binded property, the controls will dress itself to display an error. this is done only if the HasErrors is set to true.
Question:
- Is there anyone know more detail aobut the
ErrorsChanged event is raised for the binded property, the controls will dress itself to display an error
? If I binding
Address.Country
ofPerson
,will theErrorsChanged
event be raised for the binded propertyAddress.Country
or not? why? is there a way make this binding to show Errors too?<TextBox Text="{Binding Address.Country,Mode=TwoWay,ValidatesOnNotifyDataErrors=True}"/>