使用 WPF 数据网格时如何更改列标题的背景颜色 [英] How to change column header's background color when using WPF datagrid

查看:15
本文介绍了使用 WPF 数据网格时如何更改列标题的背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在使用 WPF 数据网格时更改列标题的背景颜色?需要直接修改xaml吗?

How to change column header's background color when using WPF datagrid? Need to modify xaml directly?

推荐答案

使用带有针对 DataGridColumnHeader 的 setter 的样式:

Use a style with a setter targeted at DataGridColumnHeader:

<DataGrid>
    <DataGrid.Resources>
        <Style BasedOn="{StaticResource {x:Type DataGridColumnHeader}}" TargetType="{x:Type DataGridColumnHeader}">
            <Setter Property="Background" Value="Blue" />
        </Style>
    </DataGrid.Resources>
</DataGrid>

这篇关于使用 WPF 数据网格时如何更改列标题的背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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