added samples
[windows-sources.git] / sdk / samples / WPFSamples / BusinessLayerValidation / csharp / window1.xaml
blobdb9487bf2ffc63aa4b8e857a0a575f32b6fbb27a
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">
7   <Window.Resources>
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">
12       <Style.Triggers>
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}"/>
17         </Trigger>
18       </Style.Triggers>
19     </Style>
20   </Window.Resources>
22   <StackPanel Margin="20">
23     <TextBlock FontSize="16">
24       
25     </TextBlock>
26     <TextBlock>Enter your age:</TextBlock>
27     <TextBox Style="{StaticResource textBoxInError}">
28       <TextBox.Text>
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"
35                 on the Binding.-->
36             <DataErrorValidationRule/>
37           </Binding.ValidationRules>
38         </Binding>
39       </TextBox.Text>
40     </TextBox>
41     <TextBlock>Mouse-over to see the validation error message.</TextBlock>
42   </StackPanel>
43 </Window>