【问题标题】:WPF DataGridRow custom style is dismissed when the Datagrid looses focus当 Datagrid 失去焦点时,WPF DataGridRow 自定义样式被解除
【发布时间】:2021-12-07 05:40:47
【问题描述】:

在具有多个数据网格的 WPF 表单场景中,我一直(未成功)尝试有条件地更改特定行(背景)的颜色,这种效果对用户来说意味着光学可检测的情况。

在试验期间,虽然我能够通过使用 数据触发器 和绑定或通过处理 LoadingRow 事件 正确设置(背景)颜色,但该行当网格控件失去焦点时,样式会被解除。

正如一些人所建议的,绕过这一点的唯一方法是使用确实有效的 System.HighlightBrush:尽管失去焦点,感兴趣的行仍保留其样式。

如果我遵循上述技术,有没有办法将 HighlightBrush 的颜色更改为标准系统默认浅蓝色以外的颜色?

【问题讨论】:

    标签: wpf datagrid styles highlight


    【解决方案1】:

    HighlightBrushKeyInactiveSelectionHighlightBrushKey 定义自己的画笔并将它们放入DataGridResources 字典中:

    <DataGrid ...>
        <DataGrid.Resources>
            <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent"/>
            <SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="Transparent"/>
            <SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Black"/>
        </DataGrid.Resources>
    </DataGrid>
    

    【讨论】:

    • 我会试一试,然后再回复你@mm8。非常感谢!
    猜你喜欢
    • 1970-01-01
    • 2013-04-03
    • 2012-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-20
    • 1970-01-01
    相关资源
    最近更新 更多