Click here to Skip to main content
15,895,746 members
Articles / Desktop Programming / WPF

Automatically validating business entities in WPF using custom binding and attributes

Rate me:
Please Sign up or sign in to vote.
4.75/5 (17 votes)
21 Aug 2009CPOL4 min read 70.6K   1.4K   40  
Validate your business entities in a maintainable way.
<Application x:Class="POC.Validatie.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    StartupUri="MainWindow.xaml">
    <Application.Resources>
        <ControlTemplate x:Key="validationTemplate">
                <StackPanel Orientation="Horizontal">
                    <Border BorderBrush="Green" BorderThickness="1">
                        <AdornedElementPlaceholder  x:Name="adorner" />
                    </Border>
                    <TextBlock Foreground="Red" FontSize="10pt" 
                               Text="{Binding ElementName=adorner, Path=AdornedElement.(Validation.Errors).CurrentItem.ErrorContent}" />
                </StackPanel>
        </ControlTemplate>
    </Application.Resources>
</Application>

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
Technical Lead RealDolmen
Belgium Belgium
I'm a Technical Consultant at RealDolmen, one of the largest players on the Belgian IT market: http://www.realdolmen.com

All posts also appear on my blogs: http://blog.sandrinodimattia.net and http://blog.fabriccontroller.net

Comments and Discussions