Click here to Skip to main content
15,886,873 members
Articles / Desktop Programming / WPF

Attributes-based Validation in a WPF MVVM Application

Rate me:
Please Sign up or sign in to vote.
4.88/5 (30 votes)
28 Jul 2010CPOL6 min read 224.4K   7.2K   101  
Description of a method which uses attribute to perform user entry validation in a WPF MVVM application
<UserControl x:Class="WpfFormsWithValidationDemo.View.CompanyFormView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <TextBlock Grid.Row="0"
                   Grid.Column="0"
                   Text="Name:" />
        <TextBlock Grid.Row="1"
                   Grid.Column="0"
                   Text="Address:" />

        <TextBox Grid.Row="0"
                 Grid.Column="1"
                 Text="{Binding Name, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}" />
        <TextBox Grid.Row="1"
                 Grid.Column="1"
                 Text="{Binding Address, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}" />
    </Grid>
</UserControl>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
Software Developer (Junior)
France France
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions