Click here to Skip to main content
11,568,017 members (43,668 online)
Click here to Skip to main content

Custom ValidationSummary with Data Form - Silverlight 4

, 13 Sep 2010 CPOL 28.2K 1.1K 6
Rate this:
Please Sign up or sign in to vote.
Custom Validation Summary by hiding default validation summary of data form


Thanks to all members.

I have found many solutions for my issues from the CodeProject community and it's time for me to contribute!

In this article, I'm explaining how we can implement custom Validation Summary by hiding default validation summary of data form.


Following are the solutions I'm focusing on:

  1. MVVM implementation with OOD principles
  2. Domain layer design clues
  3. Custom Validation Summary
  4. Validation error's consistency

Using the Code

User Interface

The sample example has three fields to display name, address and age. Following is my UI, which is a data form. A very simple UI.


View Model Implementation

Following is the class diagram of my View Model implementation.


Here is the source code for MyViewModel class.


using System;
using System.ComponentModel.DataAnnotations;

namespace CustomValidationWithDataForm
    public class MyViewModel : ViewModelBase<person />
        public MyViewModel()
            : base()
            if (null == Data)
                this.Data = Activator.CreateInstance(typeof(Person)) as Person;
        [Required(ErrorMessage="Name should not be empty!")]
        public string Name
                return this.Data.Name;
                ValidateProperty(value, "Name");
                this.Data.Name = value;

        [Required(ErrorMessage = "Address should not be empty!")]
        public string Address
                return this.Data.Address;
                ValidateProperty(value, "Address");
                this.Data.Address = value;
        [Range(20,50,ErrorMessage="Age should be between 20 and 50!")]
        public int Age
                return this.Data.Age;
                ValidateProperty(value, "Age");
                this.Data.Age = value;


Following are the validations rules I followed in this example:

  • Name and Address should not be empty.
  • Age should be between 20 and 50 and not equal to 35(Custom Validation).
  • You can see the validation attributes in the above code snippet.

Points of Interest

Custom ValidationSummary

I have collapsed the data form specific ValidationSummary by using ValidationSummaryStyle.

See MainPage.xaml below:

<UserControl x:Class="CustomValidationWithDataForm.MainPage"
d:DesignHeight="300" d:DesignWidth="400">
<Grid x:Name="LayoutRoot" Background="White">
<Style x:Key="CustomValidationSummaryStyle" TargetType="input:ValidationSummary">
<Setter Property="Visibility" Value="Collapsed"/>
<input:ValidationSummary x:Name="CustomValidationSummary"/>
<toolkit:DataForm x:Name="myDf" Width="400" Height="400" 
Header="My Details" AutoCommit="False" AutoEdit="True" 
ValidationSummaryStyle="{StaticResource CustomValidationSummaryStyle}" >

<toolkit:DataField Label="Name:">
<TextBox x:Name="txtName" Text="{Binding Name,Mode=TwoWay}"/>
<toolkit:DataField Label="Address:">
<TextBox x:Name="txtAddress" Text="{Binding Address,Mode=TwoWay}"/>
<toolkit:DataField Label="Age:">
<TextBox x:Name="txtAge" Text="{Binding Age,Mode=TwoWay}"/>


  • 13th September, 2010: Initial post


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Shine K Velayudhan
Architect Synechron Technologies, Pune
India India
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralValidationSummary doesn't show combobox Pin
edudu9910-Jun-11 13:11
memberedudu9910-Jun-11 13:11 
GeneralThanks Pin
edudu9910-Jun-11 10:57
memberedudu9910-Jun-11 10:57 
GeneralMy vote of 3 Pin
Basarat Ali Syed30-May-11 7:12
memberBasarat Ali Syed30-May-11 7:12 
Needs more code from the attached project to be displayed.
GeneralMy vote of 3 Pin
Dmitri Nesteruk15-Sep-10 2:45
memberDmitri Nesteruk15-Sep-10 2:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150624.2 | Last Updated 13 Sep 2010
Article Copyright 2010 by Shine K Velayudhan
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid