What is IDataErrorInfo and how does it work with WPF?

While working on some custom validators in WPF, one of my employees pointed me to IDataErrorInfo. I have a sample in XAML that has a text box and a button. Based on the value in the text box, I would like the button to be either on or off. My colleague suggested that the IDataErrorInfo extension in the view of my view and writing custom logic for the "Item" and "Error" properties would solve my problem. Before I could include this in my code, it seemed to me that I should understand how IDataError information works, and what is it for implementing this interface, which provides the necessary intercepts to trigger the user verification logic? Some help with this concept will be extremely helpful!

+5
source share
3 answers

IDataErrorInfo is an interface that a class can implement to notify subscribers of errors for a particular property, as well as errors at the class level.

If you implement this for the class that was used as your DataContext (i.e.: ViewModel in MVVM), you can set UpdatesOnValidationError to true for the controls and set a custom template to display the object differently if there are errors. WPF handles plumbing for you.

Below is a short short tutorial showing the whole process .

+4
source

BookLibrary WPF Application Framework (WAF). , WPF "", .

0

, IDataErrorInfo ViewModel, . , System.ComponentModel.DataAnnotations.

, "", -, WPF, . refactorthis.net WPF Validation . IDataErrorInfo .

0

All Articles