WPF: Validation with IDataErrorInfo

IDataErrorInfo Provides the functionality to offer custom error information that a user interface can bind to, it is an interface that a class can implement in order to notify subscribers of error information for a specific property, as well as errors at the class level.

If you implement this for the class that's used as your DataContext (ie: the ViewModel in MVVM), you can set UpdatesOnValidationError to true for controls, and set a custom template to display the item differently if there are errors. WPF handles the plumbing for you. 3 simple steps and you’ll get your result.

Step 1: Create data model with IDataErrorInfo

Step 2: Databind the data to your input fields

Step 3: Customize the Error Template to get different look and feel

Attaching some screen shot..



Please find the attached code project for more details.