我有继承自 TextBox 的自定义 AutoCompleteTextBox 类。一切正常,除了显示验证错误,即控件周围的红色边框。
这是我的 Generic.xaml 中的样式。
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" />
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" />
<Setter Property="BorderBrush" Value="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="HorizontalContentAlignment" Value="Left" />
<Setter Property="Padding" Value="2" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:AutoCompleteTextBox}">
<Grid>
<Border x:Name="PART_Border" SnapsToDevicePixels="true" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
<ScrollViewer x:Name="PART_ContentHost" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
</Border>
<Popup x:Name="PART_Popup" StaysOpen="False">
<ListBox x:Name="PART_ListBox" HorizontalContentAlignment="Stretch" />
</Popup>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Background" TargetName="PART_Border" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" />
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
</Trigger>
<Trigger Property="IsReadOnly" Value="true">
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
我检查了 Snoop 实用程序,发现没有红色边框。我已经查看了 WPF 的 Generic.xaml Aero.Normal.xaml,老实说,我不知道是什么在无效文本框周围绘制了红色验证边框。
我知道以前曾提出过类似的问题,但我重新审查了所有答案,但没有一个有帮助。