1 <Window x:Class="BusinessLayerValidation.Window1"
2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4 Title="WPF IDataErrorInfo Sample" Width="350" Height="150"
5 xmlns:src="clr-namespace:BusinessLayerValidation">
8 <src:Person x:Key="data"/>
10 <!--The tool tip for the TextBox to display the validation error message.-->
11 <Style x:Key="textBoxInError" TargetType="TextBox">
13 <Trigger Property="Validation.HasError" Value="true">
14 <Setter Property="ToolTip"
15 Value="{Binding RelativeSource={x:Static RelativeSource.Self},
16 Path=(Validation.Errors)[0].ErrorContent}"/>
22 <StackPanel Margin="20">
23 <TextBlock FontSize="16">
26 <TextBlock>Enter your age:</TextBlock>
27 <TextBox Style="{StaticResource textBoxInError}">
29 <Binding Path="Age" Source="{StaticResource data}"
30 UpdateSourceTrigger="PropertyChanged">
31 <Binding.ValidationRules>
32 <!--DataErrorValidationRule checks for validation
33 errors raised by the IDataErrorInfo object
34 Alternatively, you can set ValidatesOnDataErrors="True"
36 <DataErrorValidationRule/>
37 </Binding.ValidationRules>
41 <TextBlock>Mouse-over to see the validation error message.</TextBlock>