This post is about the session calledWhat’s new in Silverlight 3 given by Mike Taulty.
Silverlight 3 has a new way for validating data. The validation rules can be set in a number of different ways:
- Throwing an exception
- Adding specific attributes to the classes properties
I specifically like the way the business rules can be applied to an object. Some samples of specifying the validation are shown below.
class Person
{
[Required(ErrorMessage = “The name of the person is required”)]
public string Name { get; set; }
[Range(18, 65, ErrorMessage = ”The person must be between 18 and 65 years old”)]
[DefaultValue(20)]
public int Age { get; set; }
}
More validation attributes are available at MSDN
The nice thing about the new version of Silverlight 3 is that the default input controls can handle these validation errors and show them to the user, this is very similar to the way we know validation controls in ASP.NET. The way in which these messages are shown is fully customizable through themes.

The screenshot above shows an example of the new Dataform which is also available in Silverlight 3. It also gives you an example of the standard way a user is informed about errors.
With the new Dataform control it is possible to automatically render the CRUD GUI for an object or list of objects.
By implementing the IEditableObject interface for an object, the following events can be handled within the class: BeginEdit, CancelEdit and EndEdit
For more information about the Dataform control see the following blog post of Mike Taulty, another post by Mike Taulty is about data validation