这似乎是 WPF 中的一个错误,但也许有人对此有答案。我有一个用于可编辑组合框的 DataTrigger。它适用于我的 TabControl 的第一个 TabItem,但不适用于第二个。如果您将第一个与第二个 TabItem 切换,则“第二个”将起作用。当您将样式完全赋予 ComboBox (ComboBox.Style ...) 时,也会发生相同的效果。
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="MainWindow"
x:Name="Window"
Title="MainWindow"
Width="640" Height="480">
<Window.Resources>
<Style TargetType="{x:Type ComboBox}">
<Setter Property="Height" Value="25" />
<Setter Property="Width" Value="125" />
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=PART_EditableTextBox, Path=IsFocused}" Value="True">
<Setter Property="BitmapEffect">
<Setter.Value>
<OuterGlowBitmapEffect GlowColor="Red" GlowSize="5" />
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Grid x:Name="LayoutRoot">
<TabControl>
<TabItem Header="TabItem1">
<Grid>
<ComboBox IsEditable="True"/>
</Grid>
</TabItem>
<TabItem Header="TabItem2">
<Grid>
<ComboBox IsEditable="True"/>
</Grid>
</TabItem>
</TabControl>
</Grid>