DataGrid Rows' Foreground color for selected item

家住魔仙堡 提交于 2019-12-23 05:12:46

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!