Reputation: 309
I created a custom error template to show validation errors. Here is my XAML:
<Style TargetType="Control" x:Key="myErrorTemplate">
<Setter Property="Validation.ErrorTemplate">
<Setter.Value>
<ControlTemplate>
<DockPanel LastChildFill="True">
<TextBlock DockPanel.Dock="Right"
Foreground="Red"
FontSize="26"
FontWeight="Bold"
Text=" !"
Margin="0,-8,0,0" />
<Border>
<AdornedElementPlaceholder Name="myControl" />
</Border>
</DockPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
<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>
This will place an exclamation mark near the TextBox when a validation error occurs. Currently this template will show an error tooltip when mouse hovers over the TextBox. I want to show tooltip also when I hover over the exclamation mark (textblock). How do I achieve this?
Upvotes: 4
Views: 879
Reputation: 18580
Try this:
<TextBlock DockPanel.Dock="Right"
Foreground="Red"
FontSize="26"
FontWeight="Bold"
Text=" !"
Margin="0,-8,0,0" >
<TextBlock.Style>
<Style TargetType="TextBlock">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=(Validation.HasError), RelativeSource={RelativeSource TemplatedParent}}" Value="True">
<Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource TemplatedParent},
Path=(Validation.Errors)[0].ErrorContent}" />
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
Upvotes: 1