added samples
[windows-sources.git] / sdk / samples / WPFSamples / BindValidation / visualbasic / window1.xaml
blob86b067eeca35dbfb64dc97b5c5186291ce78b66e
1 <Window
2   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4   xmlns:c="clr-namespace:BindValidation_VB"
5   x:Class="Window1"
6   Title="Binding Validation Sample"
7   SizeToContent="WidthAndHeight"
8   ResizeMode="NoResize">
10     <Window.Resources>
11       <c:MyDataSource x:Key="ods"/>
13       <ControlTemplate x:Key="validationTemplate">
14         <DockPanel>
15           <TextBlock Foreground="Red" FontSize="20">!</TextBlock>
16           <AdornedElementPlaceholder/>
17         </DockPanel>
18       </ControlTemplate>
20       <Style x:Key="textBoxInError" TargetType="{x:Type TextBox}">
21         <Style.Triggers>
22           <Trigger Property="Validation.HasError" Value="true">
23             <Setter Property="ToolTip"
24               Value="{Binding RelativeSource={x:Static RelativeSource.Self},
25                               Path=(Validation.Errors)[0].ErrorContent}"/>
26           </Trigger>
27         </Style.Triggers>
28       </Style>
29     </Window.Resources>
31   <Grid>
32     <Grid.ColumnDefinitions>
33       <ColumnDefinition />
34       <ColumnDefinition />
35       <ColumnDefinition />
36     </Grid.ColumnDefinitions>
37     <Grid.RowDefinitions>
38       <RowDefinition />
39       <RowDefinition />
40       <RowDefinition />
41       <RowDefinition/>
42       <RowDefinition />
43     </Grid.RowDefinitions>
45     <TextBlock
46       Grid.Row="0" Grid.ColumnSpan="2"
47       FontSize="20" Margin="8" 
48       Text="Enter a number between 21-130 or there will be a validation error:"/>
50     <Label Grid.Column="0" Grid.Row="1" FontSize="15" Margin="2"
51            Target="{Binding ElementName=textBox1}">TextBox with _custom ErrorTemplate and ToolTip:</Label>
52     <TextBox Name="textBox1" Width="50" FontSize="15"
53              Validation.ErrorTemplate="{StaticResource validationTemplate}"
54              Style="{StaticResource textBoxInError}"
55              Grid.Row="1" Grid.Column="1" Margin="2">
56       <TextBox.Text>
57         <Binding Path="Age" Source="{StaticResource ods}"
58                  UpdateSourceTrigger="PropertyChanged" >
59           <Binding.ValidationRules>
60             <c:AgeRangeRule Min="21" Max="130"/>
61           </Binding.ValidationRules>
62         </Binding>
63       </TextBox.Text>
64     </TextBox>
66     <Label Grid.Row="2" Grid.Column="0" FontSize="15" Margin="2"
67        Target="{Binding ElementName=textBox2}">TextBox with _default ErrorTemplate:</Label>
68     <TextBox Name="textBox2" Width="50" FontSize="15"
69              Grid.Row="2" Grid.Column="1" Margin="2">
70       <TextBox.Text>
71         <Binding Path="Age2" Source="{StaticResource ods}"
72                  UpdateSourceTrigger="PropertyChanged" >
73           <Binding.ValidationRules>
74             <c:AgeRangeRule Min="21" Max="130"/>
75           </Binding.ValidationRules>
76         </Binding>
77       </TextBox.Text>
78     </TextBox>
80     <TextBlock Grid.Row="3" Grid.ColumnSpan="3" FontSize="20" Margin="8" 
81                Text="The following TextBox uses the ExceptionValidationRule and UpdateSourceExceptionFilter handler:"/>
82     <Label Grid.Row="4" Grid.Column="0" FontSize="15" Margin="2"
83    Target="{Binding ElementName=textBox3}">TextBox with UpdateSourceExceptionFilter _handler:</Label>
84     <TextBox Name="textBox3" Width="50" FontSize="15"
85              Grid.Row="4" Grid.Column="1" Margin="2"
86              Validation.ErrorTemplate="{StaticResource validationTemplate}"
87              Style="{StaticResource textBoxInError}">
88       <TextBox.Text>
89         <Binding Path="Age3" Source="{StaticResource ods}"
90                  UpdateSourceTrigger="PropertyChanged">
91           <Binding.ValidationRules>
92             <ExceptionValidationRule/>
93           </Binding.ValidationRules>
94         </Binding>
95       </TextBox.Text>
96     </TextBox>
97     <CheckBox Name="cb" FontSize="15" HorizontalAlignment="Left"
98          Grid.Row="4" Grid.Column="2" Margin="5"
99          Checked="UseCustomHandler" Unchecked="DisableCustomHandler">Enable Custom Handler (see ToolTip)</CheckBox>
100   </Grid>
101 </Window>