在WPF中IsEditing = True时如何更改DataGridCell的背景 [英] How to change background of DataGridCell when IsEditing=True in WPF

查看:172
本文介绍了在WPF中IsEditing = True时如何更改DataGridCell的背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

设置背景对于 DataGridCheckBoxColumn 来说很好,但是对于 DataGridTextColumn 来说却不能。我将其设置为资源中的单元格:

Setting background works fine for DataGridCheckBoxColumn but not for DataGridTextColumn. I set it for cell in resources:

<Style TargetType="{x:Type DataGridCell}">
    <Style.Triggers>
        <Trigger Property="IsSelected" Value="True">
            <Setter Property="Background" Value="#ffff00" />
        </Trigger>

        <Trigger Property="IsEditing" Value="True">
            <Setter Property="BorderThickness" Value="1" />
            <Setter Property="BorderBrush" Value="#00ff00" />
            <Setter Property="Background" Value="#00ff00" />
        </Trigger>
    </Style.Triggers>
</Style>

此问题是否有解决方案?

Is there any solution for this issue?

推荐答案

您应该添加 magic 字符串:

<SolidColorBrush x:Key="{x:Static SystemColors.WindowBrushKey}" Color="Transparent" />

在您的资源中,例如在< Window.Resources>

in your resources, for example in <Window.Resources>.

在这种情况下,当默认分配 IsEditing = True 颜色时( White ),摘自 SystemColors 。但是随后您需要显式设置主面板或 Window 的颜色。

In this case, when IsEditing="True" color is assigned by default (White), which is taken from the SystemColors. But then you need to explicitly set the color for the main panel or for Window.

或在< DataGrid.Resources> Background = White

<DataGrid Background="White" ...>
    <DataGrid.Resources>
        <SolidColorBrush x:Key="{x:Static SystemColors.WindowBrushKey}" Color="Transparent" />
    </DataGrid.Resources>
        ... 
</DataGrid>

这篇关于在WPF中IsEditing = True时如何更改DataGridCell的背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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