Validation in WPF Using INotifyDataErrorInfo Interface

In my other article I discussed validation using IDataErrorInfo Interface. Now here in this article we are going to validate the data using INotifyDataErrorInfo.


Namespace : System.ComponentModel
INotifyDataErrorInfo comes in .NET 4.5

When there is already IDataErrorInfo Interface for validation then why .NET intoduce INotifyDataErrorInfo Interface

IDataErrorInfo only provide you the capability to return single string that specify the error belongs to a particular property. But INotifyDataErrorInfo Interface gives you more flexibility like

  • With the help of INotifyDataErrorInfo Interface you can perform server-side validation asynchronously
  • It also notify UI when the validation is completed by raising a ErrorChanged event
  • You can set multiple errors per property
  • As in IDataErrorInfo the error message can be of String type but in INotifyDataErrorInfo you can return a custom error object of some other type.
  • It also supports Cross-property errors. These are the errors which affect multiple properties. So either we can associate them with one property or all the properties of the entity.

INotifyDataErrorInfo Interface provides more flexibility in WPF validations. This interface introduce 3 things (1 property, 1 method, 1 event) to provide synchronous and asynchronous validation support.

1. HasErrors – a property, return a bool value indicating if the entity has validation error or not.
2. GetErrors(string) – a method, it take propertyname(string) as an argument and returns IEnumerable object which contains the validation errors for a single property or for the entire entity.
3. ErrorsChanged Event – This event occurs when the the validation error of a property or for the entire entity changes. In simple terms it is raised when the return value of GetErrors method changes. The return value changes whenever the errors are added, removed or modified.

This article is still in updation process.. Sorry for Inconvenience.. ComeBack soon for full understanding!!!