Introduction to Validation in Silverlight 4


Data validation is most important for data driven applications. This article talks about the basics of validation in Silverlight 4.

Following are some screen shots of how the sample application looks before and after the validation.

Before:

1.gif
 
After:
 
2.gif 

Following is an employee class which has two properties namely name and age. The properties of the employee class are validated whenever the user sets the properties. In this example, the following checks are made

For Name property : Name should not be empty and should contain only letters ("alphabets")
 
3.gif

4.gif 

For Age property : Age should be between 0 - 100

5.gif 

Following is the mainpage.xaml where you have to set the validation for the controls.

For textbox control accepting Name of employee
 
6.gif

For textbox control accepting Age of employee
 
7.gif


Similar Articles