WPF DataGrid行和列样式问题 [英] WPF DataGrid row and column Style question

查看:380
本文介绍了WPF DataGrid行和列样式问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要突出显示Datagrid的MouseOver行,这个样式似乎很简单:

I have a need to highlight the MouseOver row of the datagrid, which seems to be easy with this style:

<Style TargetType="DataGridRow">
    <Style.Triggers>
        <Trigger Property="IsMouseOver" Value="True">
            <Setter Property="Background" Value="Green"/>
        </Trigger>
    </Style.Triggers>
</Style>

问题是我还有一些只读单元格的样式,定义为:

The problem is that I also have a style for some readonly cells defined as:

<Style TargetType="DataGridCell">
    <Style.Triggers>
        <Trigger Property="IsReadOnly" Value="True">
            <Setter Property="Background" Value="LightGoldenrodYellow"/>
        </Trigger>
    </Style.Triggers>
</Style>

因此,这些只读单元格不会得到MouseOver背景。如何解决这个冲突?您的帮助非常感激。

As a result, those readonly cells don't get MouseOver background. How do I solve this conflict? Your help is much appreciated.

推荐答案

这不是冲突。 MouseOver事件适用于不可读的正常行和单元格。

It is not a conflict. The MouseOver event is intended to work for normal row and cell which is not readonly.

您应该为此问题添加MultiTrigger。

You should add a MultiTrigger for this problem.

样本:

  <MultiTrigger>
    <MultiTrigger.Conditions>
      <Condition Property="IsReadOnly" Value="true" />
      <Condition Property="IsMouseOver" Value="true" />
    </MultiTrigger.Conditions>
    <Setter Property="Background" Value="Green"/>
  </MultiTrigger>

代码适用于DataGridCell的样式。完成的代码示例将是:

The code is valid for a style for DataGridCell. The completed code sample would be:

<Style TargetType="DataGridCell">    
<Style.Triggers>        
      <MultiTrigger>
        <MultiTrigger.Conditions>
          <Condition Property="IsReadOnly" Value="true" />
          <Condition Property="IsMouseOver" Value="true" />
        </MultiTrigger.Conditions>
        <Setter Property="Background" Value="Green"/>
      </MultiTrigger>
</Style.Triggers>
</Style>

这篇关于WPF DataGrid行和列样式问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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