我有下面的边框。为什么我的TextBlock的Foreground正常工作但边框的背景始终保持不变(就好像IsDeleted属性总是为false)
<Border DockPanel.Dock="Top" BorderBrush="Black" Background="#CBE2FF" BorderThickness="2" CornerRadius="5" Padding="0" Margin="5">
<Border.Style>
<Style TargetType="{x:Type Border}">
<Style.Triggers>
<DataTrigger Binding="{Binding IsDeleted}" Value="True">
<Setter Property="Background" Value="#A00000"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Border.Style>
<TextBlock Margin="5" FontWeight="Bold" FontSize="14" Text="Queue Details">
<TextBlock.Style>
<Style TargetType="{x:Type TextBlock}">
<Style.Triggers>
<DataTrigger Binding="{Binding IsDeleted}" Value="True">
<Setter Property="Foreground" Value="White"/>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
</Border>
答案 0 :(得分:40)
您已在边框上明确设置背景值。这比触发器更优先。删除Background="#CBE2FF"
并将其带入样式。
<Border.Style>
<Style TargetType="{x:Type Border}">
<Setter Property="Background" Value="#CBE2FF"/>
...
这会有所帮助。