我有一个绑定(bind)到集合的数据网格。我已将以下行样式应用于数据网格:
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Style.Triggers>
<DataTrigger Binding="{Binding Status}" Value="Down">
<Setter Property="Background" Value="Red" />
<Setter Property="Foreground" Value="White" />
</DataTrigger>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding Status}" Value="Down" />
<Condition Binding="{Binding RelativeSource={RelativeSource Mode=Self}, Path=IsSelected}" Value="True" />
</MultiDataTrigger.Conditions>
<Setter Property="Background" Value="Green" />
<Setter Property="Foreground" Value="White" />
</MultiDataTrigger>
</Style.Triggers>
</Style>
</DataGrid.RowStyle>
数据触发器正在工作,但多重数据触发器不起作用。失败的条件是检查 datagridrow 上的 IsSelected 是否为 true。如果我更改它,使其使用始终返回 true 的值转换器,我将看到行显示为绿色。
基本上,我希望数据对象的 status 属性设置为红色的行,但是当我选择这些行时,它们需要为绿色(或实际上为深红色),而不是默认的蓝色。
最佳答案
您的绑定(bind)可能非常好。但 DataGrid 使用 SystemColors.HighlightBrush 和 SystemColors.HighlightTextBrush 来突出显示选定的行。要更改所选行的颜色,您只需覆盖 DataGrid 的画笔,如下所示:
<DataGrid.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent"/>
</DataGrid.Resources>
这样您应该能够看到触发器设置的背景颜色。
希望这有帮助!
关于wpf - 后台的 DataGridRow MultiDataTrigger : IsSelected condition not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5763749/