Why is my Validatioin Rule not being invoked?
RogerSchlueter-7899
1,326
Reputation points
Here is the xaml for a textbox on a WPF window:
<TextBox
x:Name="txtTitle"
HorizontalAlignment="Stretch"
Margin="0,5,5,0">
<TextBox.Text>
<Binding
Path="Title"
UpdateSourceTrigger="LostFocus">
<Binding.ValidationRules>
<self:TextRequired />
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
<TextBox.Style>
<Style
TargetType="TextBox">
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="true">
<Setter Property="ToolTip" Value="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=(Validation.Errors)/ErrorContent}"/>
</Trigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>
This TextBox gets the focus when the window is loaded:
txtTitle.Focus()
which is evident by the blinking cursor in the TextBox. Yet the Validation Rule is NOT be invoked when the curson moves to a different control on the window. Putting this in code behind as a check:
Private Sub txtTitle_LostFocus(sender As Object, e As RoutedEventArgs) Handles txtTitle.LostFocus
Debug.WriteLine("LostFocus")
End Sub
confirms that the LostFocus event is firing. So why is the validation rule not being invoked?
Sign in to answer