The Ins and Outs of IDataErrorInfo and WPF Binding

While implementing the business rules to check object validity, I used IDataErrorInfo and Binding.ValidatesOnDataErrors=true to get the validation information to the user.

In some cases I noticed that the WPF Binding didn’t realize that the errors on an object changed. Quickly it became clear that WPF is only checking the IDataErrorInfo when setting or retrieving a value. Which doesn’t happen for a specific property, if a different property, that has influence on the validity of the former property, changes. In retrospect quite obvious.

The solution was to implement INotifyPropertyChanged and trigger Changed events for all affected properties.

I’ve coded a little demo application to show the problem and showcase the solution:

Test application screenshot

The screenshot shows the test app after trying to trigger validation errors on different implementations by changing the illegal value to the input value. Only the INotifyPropertyChanged with additional notifications (on the lower right) detects the invalid value.

Download the solution archive.

Leave a Reply