<Window x:Class="_2nd_DataBindingTest.CustomValidation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Valid="clr-namespace:_2nd_DataBindingTest.Validation" Title="CustomValidation" Height="300" Width="300"> <Grid> <Grid.Resources> <ControlTemplate x:Key="ValidationTemplate2"> <Border BorderBrush="Red" BorderThickness="5" CornerRadius="7"> <AdornedElementPlaceholder /> </Border> </ControlTemplate> </Grid.Resources> <!--This is an implementation of a custom validation with a Regex using the general validation rule in the code behind and pass the parameters here in XAML--> <Label Content="Email:" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top"/> <TextBox HorizontalAlignment="Left" Height="23" Margin="59,14,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="223" Name="txtCV"> <TextBox.Text> <Binding Path="Email" UpdateSourceTrigger="LostFocus"> <Binding.ValidationRules> <Valid:RegexValidation x:Name="rgv" Expression="^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$" ErrorMessage="Email is not valid!" /> </Binding.ValidationRules> <Binding.ValidatesOnDataErrors>True</Binding.ValidatesOnDataErrors> </Binding> </TextBox.Text> <TextBox.Style> <Style TargetType="TextBox"> <Style.Triggers> <Trigger Property="Validation.HasError" Value="True"> <Setter Property="ToolTip" Value="There is an error!" /> <----- </Trigger> </Style.Triggers> </Style> </TextBox.Style> </TextBox> <CheckBox Content="CheckBox" HorizontalAlignment="Left" Margin="10,42,0,0" VerticalAlignment="Top"/> </Grid> </Window>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)