【发布时间】:2014-06-23 17:47:04
【问题描述】:
我创建了一个自定义错误模板来显示验证错误。这是我的 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>
当发生验证错误时,这将在 TextBox 附近放置一个感叹号。目前,当鼠标悬停在文本框上时,此模板将显示错误工具提示。当我将鼠标悬停在感叹号(文本块)上时,我也想显示工具提示。我如何做到这一点?
【问题讨论】: