- Multiple field validator in WPF search form
- <TextBox Grid.Column="1" Grid.Row="3" Name="tbxPartNumber" Margin="6">
- <TextBox.Text>
- <Binding Path="SelectedPartNumber" UpdateSourceTrigger="PropertyChanged">
- <Binding.ValidationRules>
- <local:RequiredTextValidation/>
- </Binding.ValidationRules>
- </Binding>
- </TextBox.Text>
- </TextBox>
- <Window x:Class="Test.Dialogs.SearchDialog"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns:sys="clr-namespace:System;assembly=mscorlib"
- xmlns:diag="clr-namespace:Test.Dialogs"
- xmlns:m="clr-namespace:HB.Xaml"
- Title="Search" SizeToContent="WidthAndHeight" ResizeMode="NoResize"
- Name="Window" DataContext="{Binding RelativeSource={RelativeSource Self}}">
- <Grid>
- <Grid.Resources>
- <Style x:Key="BaseStyle" TargetType="{x:Type FrameworkElement}">
- <Setter Property="Margin" Value="3"/>
- <Setter Property="VerticalAlignment" Value="Center"/>
- </Style>
- <Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource BaseStyle}"/>
- <Style TargetType="{x:Type ComboBox}" BasedOn="{StaticResource BaseStyle}"/>
- <Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource BaseStyle}"/>
- <Style TargetType="{x:Type Button}" BasedOn="{StaticResource BaseStyle}"/>
- </Grid.Resources>
- <Grid.ColumnDefinitions>
- <ColumnDefinition/>
- <ColumnDefinition/>
- </Grid.ColumnDefinitions>
- <Grid.RowDefinitions>
- <RowDefinition Height="Auto"/>
- <RowDefinition Height="Auto"/>
- <RowDefinition Height="Auto"/>
- <RowDefinition Height="Auto"/>
- </Grid.RowDefinitions>
- <Grid.Children>
- <TextBlock Grid.Column="0" Grid.Row="0" Text="Scope:"/>
- <ComboBox Grid.Column="1" Grid.Row="0" ItemsSource="{m:EnumItems {x:Type diag:SearchDialog+ScopeMode}}">
- <ComboBox.SelectedItem>
- <Binding Path="Scope">
- <Binding.ValidationRules>
- <diag:HasSelectionValidationRule />
- </Binding.ValidationRules>
- </Binding>
- </ComboBox.SelectedItem>
- </ComboBox>
- <TextBlock Grid.Column="0" Grid.Row="1" Text="Direction:"/>
- <ComboBox Grid.Column="1" Grid.Row="1" ItemsSource="{m:EnumItems {x:Type diag:SearchDialog+DirectionMode}}">
- <ComboBox.SelectedItem>
- <Binding Path="Direction">
- <Binding.ValidationRules>
- <diag:HasSelectionValidationRule />
- </Binding.ValidationRules>
- </Binding>
- </ComboBox.SelectedItem>
- </ComboBox>
- <TextBlock Grid.Column="0" Grid.Row="2" Text="Expression:"/>
- <TextBox Name="tb" Grid.Column="1" Grid.Row="2">
- <TextBox.Text>
- <Binding Path="Expression" UpdateSourceTrigger="PropertyChanged">
- <Binding.ValidationRules>
- <diag:StringNotEmptyValidationRule />
- </Binding.ValidationRules>
- </Binding>
- </TextBox.Text>
- </TextBox>
- <Button Grid.Column="1" Grid.Row="3" Content="Search" Click="Search_Click"/>
- </Grid.Children>
- </Grid>
- </Window>