我是一个WPF文本框验证的助手。我定义了以下模板:
<Style x:Key="textBoxInError" TargetType="{x:Type TextBox}" BasedOn="{StaticResource StyleTextBox}">
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="true">
<Setter Property="ToolTip"
Value="{Binding RelativeSource={x:Static RelativeSource.Self},
Path=(Validation.Errors)[0].ErrorContent}"/>
<Setter Property="Background" Value="{StaticResource TextBox_ErrorBackgroundBrush}"/>
<Setter Property="BorderBrush" Value="{StaticResource TextBox_ErrorBorderBrush}"/>
<Setter Property="BorderThickness" Value="2"/>
</Trigger>
</Style.Triggers>
<Setter Property="Validation.ErrorTemplate">
<Setter.Value>
<ControlTemplate>
<DockPanel>
<TextBlock DockPanel.Dock="Right" Foreground="Red" FontSize="20" Text="!"/>
<AdornedElementPlaceholder/>
</DockPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
文本框位于选项卡中的表单上。 一切都正常,但是当我选择其他选项卡时,“!”文本块仍然可见。在许多其他情况下也观察到此行为-当展开器展开时等等,感叹号始终保持在同一位置可见,尽管文本框未显示。