【发布时间】:2009-07-28 13:43:27
【问题描述】:
我正在使用 WPF 验证进行 TextBox 验证。我已经定义了这个模板:
<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>
TextBox 位于 TabItem 中的表单上。 一切正常,但“!”当我选择其他 TabItems 时,TextBlock 保持可见。在许多其他情况下会观察到这种行为 - 当扩展器展开等时。虽然没有显示 TextBox,但 Excklamation 始终保持在同一位置可见。
【问题讨论】:
标签: wpf validation templates focus