Silverlight Feeds - All your Silverlight feeds in one place.

Sponsors

Saturday, July 18, 2009

What’s New In Silverlight 3 - Validation

by jesseliberty via Jesse Liberty - Silverlight Geek on 7/18/2009 6:05:00 PM

Data Validation is fully implemented in Silverlight 3, utilizing the object the input control is bound to as the decider of what is valid, and the Visual State Machine to provide feedback to the user.

The process is best understood as a sequence of steps,

    1.    Add an input control to your page.
    2.    Bind the input control to a data object using two way binding.   Set both ValidatesOnException and NotifyOnValidationError to true on the data object

 data validation.Valid1

    3.    Test the data for validity and throw an exception for invalid data in any of the following three places:
    ?    Binding Type Converter
    ?    Data bound object’s set accessor for the corresponding property
    ?    validation attribute applied to the data object or member

If you throw an exception put a meaningful message into the exception’s message property

data validation.Valid2

For example, the data object that a registration form is bound to might have a Password2 property that tests to make sure the user has entered the same password twice:

   1: public string Password2
   2:   {
   3:     get { return pw2; }
   4:     set 
   5:     {
   6:       if ( value != Password1)
   7:       {
   8:         throw new ArgumentException( "Passwords must match. ");
   9:       }
  10:       pw2 = value;
  11:       NotifyPropetyChanged( "Password2" );
  12:     }
  13:   }

4. The DataBinding engine will convert the exception to a visual state change notification to your control, which must already support the Visual State Group: ValidationStates which consists of
    ?    Valid
    ?    InvalidUnfocused
    ?    InvalidFocused

data validation.Valid3

When the visual state changes, the Visual State Manager calls the appropriate storyboard as usual. The effect is that the UI is updated to inform the user of the validation problem,

data validation.Validation2

 

 

 

 

 

 

The following controls are provided with default control templates (which of course you can modify) to support Data Validation
    ?    Textbox
    ?    PasswordBox
    ?    CheckBox
    ?    RadioButton
    ?    ListBox
    ?    ComboBox

The Silverlight Learn page has a video on Data Validation and another specifically on Password Validation, with more to come, and there are in-depth  mini-tutorials on data validation here and especially here

[ Working Demo Follows ]

PreviousBased-on Styles        More: Easing Is Easier    

[We are transitioning the DocumentWiki into linked blog pages for better access and visibility]

email it!bookmark it!digg it!

Original Post: What’s New In Silverlight 3 - Validation

Subscribe

New Feed

Product Spotlight

Recently Updated Sources

Legal Note

The content of the postings is owned by the respective author. Silverlight Feeds is not responsible for the contents of the postings. This site is automatically generated and cannot be reviewed for abusive content. If you find abusive content on Silverlight Feeds, please contact us. Designated trademarks and brands are the property of their respective owners. All rights reserved.

Advertise with us