Silverlight MVVM, RIA, and Validation

Posted Sun, May 1 2011 15:43 by Deborah Kurata

One of the biggest challenges of implementing validation in Silverlight is finding the appropriate technique based on your architecture and goals. There are lots of choices and lots of examples, but not all examples work in all scenarios. Plus many examples demonstrate techniques that are no longer necessary or valid in the current version of Silverlight or when using WCF RIA services.

Below are a set of posts on techniques for performing validation with Silverlight 4.0 using MVVM, WCF RIA Services, and custom business objects.

A few things to keep in mind if you are using Silverlight and WCF RIA Services:

  1. In most cases, the code should not need to throw exceptions for validation errors.
  2. The latest version of Silverlight/RIA provides automatic validation and a built-in validation error dictionary, so you do not have to write any code to build or populate validation errors.

The last point is an important one because there are videos and posts that go through the pages and pages of code required to manage your own validation and validation error dictionary. While this code is necessary and useful if you are using WCF directly, it is not necessary if you are using WCF RIA Services.

Here are the links:

Click on a link to navigate to the desired post.

Enjoy!

Comments

# Silverlight MVVM, WCF RIA Services Simple Sample Application

Sunday, May 01, 2011 5:52 PM by Deborah's Developer MindScape

This post provides a simple Silverlight MVVM, WCF RIA Services sample application that is used to demonstrate

# Silverlight/WCF RIA Single Property Validation

Sunday, May 01, 2011 9:01 PM by Deborah's Developer MindScape

When you identify the validation scenarios for your application, you will find that some only require

# re: Silverlight MVVM, RIA, and Validation

Sunday, May 01, 2011 10:28 PM by Olivier

One big problem with validations is how to validate "last" field the user is always within while she click the "ok" button of the dialog.. Depending on scenarios, the "last" field does not lost focus and then is not validated.

Playing a bit with all this validation stuff and trying to implement it in real application let me see there are some problems of this kind..

Have you some advice to give ?

thanks in advanve (for the posts, and perhaps for your answer :-) ).

# re: Silverlight MVVM, RIA, and Validation

Monday, May 02, 2011 12:05 AM by Deborah Kurata

Hi Oliver -

Using the sample application along with the changes to support single field validation, you should find that the data is also automatically validated before the submit. So the "last" field issue should not be a problem.

Try the sample code, adding in validation attributes as defined in this link: msmvps.com/.../silverlight-wcf-ria-single-property-validation.aspx

And see if it is still a problem for you.

Hope this helps.

# Silverlight MVVM, RIA, and Validation - Deborah's Developer MindScape

Monday, May 02, 2011 2:12 PM by DotNetShoutout

Thank you for submitting this cool story - Trackback from DotNetShoutout

# Silverlight Validation: Resource File

Tuesday, May 03, 2011 2:04 AM by Deborah's Developer MindScape

Resource files are a great way to manage strings, especially if you need to support multiple languages

# Silverlight/WCF RIA Validation: Metadata Class

Wednesday, May 04, 2011 1:06 AM by Deborah's Developer MindScape

Data annotation attributes are a great way to add single property validation to your Silverlight/WCF

# re: Silverlight MVVM, RIA, and Validation

Saturday, July 09, 2011 5:06 AM by SUZIE

Bravo very beautiful blog ! Thank's

# re: Silverlight MVVM, RIA, and Validation

Saturday, July 09, 2011 5:13 AM by suzie

Bravo very beautiful blog ! Thank's

# re: Silverlight MVVM, RIA, and Validation

Wednesday, November 16, 2011 7:53 PM by Ashwin

Is there any way to also addin async validation in ViewModel? i.e. to check if the entered email address already exists in the database?

Leave a Comment

(required) 
(required) 
(optional)
(required) 
If you can't read this number refresh your screen
Enter the numbers above: