Validating data
Data binding provides automatic updates from a source to a target (and vice versa in a two way binding). Some of these values are provided by some user of the system; consequently, not all values are valid. The binding system should have ways to catch such errors and allow the application to communicate to the user those errors. This is the role of data validation. In this recipe, we'll look at the validation support in data binding scenarios.
Getting ready
Make sure Visual Studio is up and running.
How to do it...
We'll create a simple entry form that validates its inputs according to some application-specific rules.
Create a new WPF application named
CH06.ValidatingData
.Add a new class to be used as a data object named
Person
. Implement it as follows:class Person : INotifyPropertyChanged { protected virtual void OnPropertyChanged(string propName) { var pc = PropertyChanged; if(pc != null) pc(this, new PropertyChangedEventArgs(propName)); } string...