zoukankan      html  css  js  c++  java
  • 【WPF】通过修改dataGrid的cell的style,改变选中行失去焦点时的颜色

    <Style  TargetType="{x:Type DataGridCell}">
                <Style.Triggers>
                    <Trigger  Property="IsSelected" Value="true">
                        <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" />
                        <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}" />
                        <Setter Property="BorderBrush" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" />
                    </Trigger>
                    <MultiDataTrigger>
                        <MultiDataTrigger.Conditions>
                            <Condition Binding="{Binding IsSelected, RelativeSource={RelativeSource Self}}" Value="True" />
                            <Condition Binding="{Binding IsKeyboardFocusWithin, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}, Mode=FindAncestor}}" Value="False" />
                        </MultiDataTrigger.Conditions>
                        <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" />
                        <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}" />
                        <Setter Property="BorderBrush" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" />
                    </MultiDataTrigger>
                </Style.Triggers>
            </Style>

     以下是仅修改选中行颜色(之前一直修改失败,原因是修改了RowStyle,这个会被CellStyle替换,故需要直接修改CellStyle

    <DataGrid.CellStyle>  
        <Style TargetType="DataGridCell">  
            <Setter Property="BorderThickness" Value="0"/>  
            <Setter Property="MinWidth" Value="85"/>     
            <Style.Triggers>  
                <Trigger Property="IsSelected" Value="True">  
                    <Setter Property="Background" Value="LightBlue"/>  
                    <Setter Property="Foreground" Value="White"/>  
                 </Trigger>  
             </Style.Triggers>  
         </Style>  
    </DataGrid.CellStyle>  
  • 相关阅读:
    .NET 动态脚本语言
    webParts与Web部件
    比较JqGrid与XtraGrid
    XtraGrid滚轮翻页
    Python------继承
    Python 私有化类的属性
    Python print 输出不换行,只有空格
    Python--函数参数类型
    手推FP-growth (频繁模式增长)算法------挖掘频繁项集
    Python 返回多个值+Lambda的使用
  • 原文地址:https://www.cnblogs.com/mqxs/p/10856361.html
Copyright © 2011-2022 走看看