xml 边框背景上的 Style.DataTrigger
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3373857/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Style.DataTrigger on Border background
提问by Miles
I have the border below. Why would the Foreground of my TextBlock work correctly but the Background of the border always stay the same (as if the IsDeleted property is always false)
我有下面的边框。为什么我的 TextBlock 的前景可以正常工作,但边框的背景始终保持不变(好像 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>
回答by HCL
You have explicitely set the background value on the border. This has more priority than the trigger. Remove the Background="#CBE2FF"and take it into the style.
您已经明确设置了边框上的背景值。这比触发器具有更高的优先级。取下Background="#CBE2FF"并将其带入样式中。
<Border.Style>
<Style TargetType="{x:Type Border}">
<Setter Property="Background" Value="#CBE2FF"/>
...
This will help.
这会有所帮助。

