- Age > Min age
- Age < Max age
- Age should only be numeric.
Follow the below steps to implement.
1) Create a WPF project and Add a class (I've used 'AgeRangeValidation' as the name).
2) Bring System.Windows.Controls namespace into scope.
3) Inherit from the ValidationRule class and implement the abstract method Validate
4) Add Automatic properties to set the Min and Max ages.
5) Add code as follows to validate for non numeric characters and age against the specified range.
6) Create a simple UI containing components to validate. In this example I've used two text boxes and a button.
7) Download the File containing in the following link and Add code to the XAML file of the UI you created using the attachment as a guidance.
After adding the code to the XAML file of the UI, the fields will be validated as the following screen shots.
Great :)
ReplyDelete