zoukankan      html  css  js  c++  java
  • WPF DataGrid ListView 等等 改变 选中行 颜色;以及 不变的原因

    WPF中改变选中行的颜色是很简单的,就是用触发器:比如:以DataGrid为例: DataGrid.RowStyle Style TargetType= DataGridRow SetterProperty= Background Value= White / Style .Triggers TriggerProperty= IsMouseOver Value= True SetterProperty= Background Value= LightGray / /Trigger TriggerPrope

      

      WPF中改变选中行的颜色是很简单的,就是用触发器:比如:以DataGrid为例:

    <DataGrid.RowStyle >
                                    <Style TargetType="DataGridRow">
                                        <Setter Property="Background" Value="White"/>
                                        <Style.Triggers>
                                            <Trigger Property="IsMouseOver" Value="True">
                                                <Setter Property="Background" Value="LightGray"/>
                                            </Trigger>
                                            <Trigger Property="IsSelected" Value="True">
                                                <Setter Property="Background" Value="LightGray"/>
                                                <Setter Property="Foreground" Value="Red"/>
                                            </Trigger>
                                        </Style.Triggers>
                                    </Style>                                
        </DataGrid.RowStyle>

     

      但是,我告诉你,如果你没有设置cellStyle,你将会发现上面的代码“貌似”不工作,没用。这一点对 ListView 等等相似控件都是一样的。

      事实上,上面代码已经起作用了。IsSelected确实被触发了。问题在哪呢?

      答案正确,就在CellStyle上。因为RowStyle 的背景改变了,但CellStyle没变,你是看不出来的。

      也就是RowStyle很冤,因为CellStyle是在其上的。所以会被覆盖。原因就是“黑人”“白人”穿着“黑衣服”看起来都是黑的。

      改变的方法如下:

      加入CellStyle:

    <DataGrid.CellStyle >
                                    <Style TargetType="DataGridCell">
                                        <Style.Triggers >
                                            <Trigger Property="IsSelected" Value="True">
                                                <Setter Property="Background" Value="Red"></Setter>
                                            </Trigger>
                                        </Style.Triggers>
                                    </Style>
    </DataGrid.CellStyle>

  • 相关阅读:
    /etc/sysctl.conf 控制内核相关配置文件
    python 并发编程 非阻塞IO模型
    python 并发编程 多路复用IO模型
    python 并发编程 异步IO模型
    python 并发编程 阻塞IO模型
    python 并发编程 基于gevent模块 协程池 实现并发的套接字通信
    python 并发编程 基于gevent模块实现并发的套接字通信
    python 并发编程 io模型 目录
    python 并发编程 socket 服务端 客户端 阻塞io行为
    python 并发编程 IO模型介绍
  • 原文地址:https://www.cnblogs.com/bdbw2012/p/3914262.html
Copyright © 2011-2022 走看看