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>

  • 相关阅读:
    linux卸载mysql
    【Linux/Oracle】ORA-00031:标记要终止的会话 解决
    linux上 oracle数据库的密码过期-解决
    SYSTEM表空间满,解决方法
    Oracle 撤回已经提交的事务
    关于MySQL取不到数据
    解决mysql只能通过localhost而不能使用本机ip访问的问题
    linux 卸载php,史上最详情
    关于支付宝免密代扣申请(全),小程序,公众号,php
    mcrypt_module_open 微信小程序 php7不能使用的问题
  • 原文地址:https://www.cnblogs.com/bdbw2012/p/3914262.html
Copyright © 2011-2022 走看看