问题
I have a RowStyle defined for my DataGrid to change the Foreground color to red for items in my grid that have a rejected status or Reject_X or Reject_Y:
<Style TargetType="DataGridRow">
<Style.Triggers>
<DataTrigger Binding="{Binding Status}" Value="{x:Static StatusTypes:Status.Reject_X}">
<Setter Property="Foreground" Value="Red"/>
</DataTrigger>
<DataTrigger Binding="{Binding Status}" Value="{x:Static StatusTypes:Status.Reject_Y}">
<Setter Property="Foreground" Value="Red"/>
</DataTrigger>
</Style.Triggers>
</Style>
This style works fine except the selected item's foreground color is black not red. So, I need to know how to style the selected item so that the Foreground color is also red. I.e.
if the item is selected AND the status equals Reject_X or Reject_Y then set Foreground to Red.
回答1:
I would look up multi data triggers. That should give you what you want.
回答2:
I think something like this should do it. I would put similar MultiTriggers on your DataGridRow style as well...
<Style TargetType="DataGridCell">
<Style.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsSelected" Value="True"/>
<Condition Binding="{Binding Status}" Value="{x:Static StatusTypes:Status.Reject_X}"/>
</MultiTrigger.Conditions>
<Setter Property="Foreground" Value="Red"/>
</MultiTrigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsSelected" Value="True"/>
<Condition Binding="{Binding Status}" Value="{x:Static StatusTypes:Status.Reject_Y}"/>
</MultiTrigger.Conditions>
<Setter Property="Foreground" Value="Red"/>
</MultiTrigger>
</Style.Triggers>
</Style>
来源:https://stackoverflow.com/questions/11418664/datagrid-rows-foreground-color-for-selected-item