Silverlight basics. Validation. Part 1. DataAnnotations & ValidatesOnExceptions

    • Silverlight
    • XAML
    • Validation
  • modified:
  • reading: 8 minutes

Silverlight 4 has some new ways for validate input values (some new approaches to implement validation in your application). First approach is DataAnnotation. In this case you should describe validation rules with attributes. Two other ways (both of them is came with Silverlight 4) – you should implement one of interfaces for your ViewModel: IDataErrorInfo or INotifyDataErrorInfo. I want to talk about all of these approaches, about pros and cons of using each of them. Goal of this article to get a best way to implement validation of input values in my and your applications. This part of article about DataAnnotations.

Background

I have example. I want to describe all of these approaches on simple control “change password”.

Capture

It has two controls PasswordBox, one button and ValidationSummary. Each sample will have own ViewModel, but XAML of UserControl will be the same:

```xml New Password: New Password Confirmation: