You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
3.2 KiB
69 lines
3.2 KiB
<Window x:Class="BindingValidationRuleSample.MainWindow"
|
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
|
xmlns:local="clr-namespace:BindingValidationRuleSample"
|
|
xmlns:model="clr-namespace:BindingValidationRuleSample.Model"
|
|
xmlns:validation="clr-namespace:BindingValidationRuleSample.Validation"
|
|
xmlns:converter="clr-namespace:BindingValidationRuleSample.Converter"
|
|
mc:Ignorable="d"
|
|
Title="MainWindow" Height="200" Width="300">
|
|
<Window.DataContext>
|
|
<model:Student/>
|
|
</Window.DataContext>
|
|
<Window.Resources>
|
|
<converter:ButtonTextBrush x:Key="cvtAgeToBrush"/>
|
|
</Window.Resources>
|
|
|
|
<Grid>
|
|
<Grid.ColumnDefinitions>
|
|
<ColumnDefinition Width="Auto"/>
|
|
<ColumnDefinition Width="*"/>
|
|
</Grid.ColumnDefinitions>
|
|
<Grid.RowDefinitions>
|
|
<RowDefinition Height="Auto"/>
|
|
<RowDefinition Height="Auto"/>
|
|
<RowDefinition Height="Auto"/>
|
|
<RowDefinition Height="*"/>
|
|
</Grid.RowDefinitions>
|
|
|
|
<TextBlock Grid.Column="0" Grid.Row="0" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="10,2"
|
|
Text="Name: "/>
|
|
<TextBlock Grid.Column="0" Grid.Row="1" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="10,2"
|
|
Text="Age: "/>
|
|
<TextBlock Grid.Column="0" Grid.Row="2" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="10,2"
|
|
Text="Phone Number: "/>
|
|
|
|
<TextBox Grid.Column="1" Grid.Row="0" Margin="5"
|
|
Text="{Binding Name, Mode=TwoWay}"/>
|
|
<TextBox x:Name="tbxAge" Grid.Column="1" Grid.Row="1" Margin="5"
|
|
ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}"
|
|
Foreground="{Binding Path=Age, Mode=TwoWay, Converter={StaticResource cvtAgeToBrush}}">
|
|
<TextBox.Text>
|
|
<Binding Path="Age"
|
|
Mode="TwoWay"
|
|
UpdateSourceTrigger="PropertyChanged">
|
|
<Binding.ValidationRules>
|
|
<validation:AgeRangeException/>
|
|
</Binding.ValidationRules>
|
|
</Binding>
|
|
</TextBox.Text>
|
|
</TextBox>
|
|
<TextBox Grid.Column="1" Grid.Row="2" Margin="5" Foreground="Blue"
|
|
Text="{Binding PhoneNumber, Mode=TwoWay}"/>
|
|
|
|
<Grid Grid.Column="0" Grid.Row="4" Grid.ColumnSpan="2" Height="30">
|
|
<Grid.ColumnDefinitions>
|
|
<ColumnDefinition/>
|
|
<ColumnDefinition/>
|
|
<ColumnDefinition/>
|
|
<ColumnDefinition/>
|
|
</Grid.ColumnDefinitions>
|
|
|
|
<Button Grid.Column="2" Content="OK" Margin="5 3"
|
|
Foreground="{Binding ElementName=tbxAge, Path=Foreground}"/>
|
|
<Button Grid.Column="3" Content="Cancel" Margin="5 3"/>
|
|
</Grid>
|
|
</Grid>
|
|
</Window>
|
|
|