WPF DataGridRow IsSelected 触发器 [英] WPF DataGridRow IsSelected Triggers

查看:108
本文介绍了WPF DataGridRow IsSelected 触发器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望将 DataGrid 中行的选定样式从默认的深蓝色和白色文本更改为实际依赖于行中现有的前景色,如下所示:

I Am looking to change the selected style of the rows in my DataGrid away from that default dark blue and white text to actually depend upon the existing Foreground color in the row like this:

<MultiDataTrigger>
  <MultiDataTrigger.Conditions>
    <Condition Property="Foreground" Value="Navy" />
    <Condition Property="IsSelected" Value="True" />
  </MultiDataTrigger.Conditions>
  <MultiDataTrigger.Setters>
    <Setter Property="Background" Value="LightSkyBlue" />
  </MultiDataTrigger.Setters>
</MultiDataTrigger>

<MultiDataTrigger>
  <MultiDataTrigger.Conditions>
    <Condition Property="Foreground" Value="Red" />
    <Condition Property="IsSelected" Value="True" />
  </MultiDataTrigger.Conditions>
  <MultiDataTrigger.Setters>
    <Setter Property="Background" Value="LightGoldenrodYellow" />
  </MultiDataTrigger.Setters>
</MultiDataTrigger>

对于其他控件,我可以找到包含设置所选样式的触发器的 ControlTemplate,但我找不到适合 DataGridRow 的模板.有谁知道里面设置的模板是什么?

For other controls I am able to find a ControlTemplate that contains triggers that set the selected style, but I cannot find the proper template for a DataGridRow. Does anyone know what template that is set in?

推荐答案

如果您只需要更改 DataGrid 中选定行的背景颜色,您应该使用 DataGridCell 的样式来实现.

If you need only change background color for selected row in DataGrid you should achieve this with style for DataGridCell.

    <Style TargetType="{x:Type DataGridCell}">
        <Style.Triggers>
            <Trigger Property="DataGridCell.IsSelected"
                     Value="True">
                <Setter Property="Background"
                        Value="LightGreen" />

                <Setter Property="Foreground"
                        Value="Black" />
            </Trigger>
        </Style.Triggers>
    </Style>

这篇关于WPF DataGridRow IsSelected 触发器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆