Reputation: 2282
I have a window like
<Window.Resources>
<ControlTemplate x:Key="ValidationTemplate">
<DockPanel>
<TextBlock Foreground="Red" FontSize="20">!</TextBlock>
<AdornedElementPlaceholder/>
</DockPanel>
</ControlTemplate>
<Style x:Key="TextBoxInError" TargetType="{x:Type TextBox}">
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="true">
<Setter Property="ToolTip"
Value="{Binding RelativeSource={x:Static RelativeSource.Self},
Path=(Validation.Errors)[0].ErrorContent}"/>
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
<TextBox x:Name="SupportFolder"
Validation.ErrorTemplate="{StaticResource ValidationTemplate}"
Style="{StaticResource TextBoxInError}"
Padding="2">
<TextBox.Text>
<Binding Path="Preferences.SupportFolder" Mode="TwoWay" UpdateSourceTrigger="LostFocus">
<Binding.ValidationRules>
<local:FolderExistsValidationRule ValidationStep="RawProposedValue"/>
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
</TextBox>
So my impression is that when the input for the TextBox
is in error that there will be a small red exclamation mark to the left of the TextBox
and because of the Style
triggers there will be a ToolTip
displaying the error. The ToolTip
works but I don't see the exclamation point indicating the error. I took this code from the Microsoft Samples but I cannot for the life of me see where I have made a mistake. The sample works (Data Binding -> BindingValidation) but I cannot seem to reproduce the code. Would someone act as a second pair of eyes and see what I am doing wrong?
Upvotes: 0
Views: 49
Reputation: 169160
You should dock the TextBlock
in the error template to the left or right:
<TextBlock Foreground="Red" FontSize="20" DockPanel.Dock="Right">!</TextBlock>
Using your current markup, the TextBlock
will end up "under" the adorned element.
Upvotes: 1