简体   繁体   English

WPF工具包DataGrid如何设置列标题SelectionBackground?

[英]WPF Toolkit DataGrid how do I set Column Header SelectionBackground?

I would just like to change the background of the column headers in the datagrid to Blue with White text. 我只想将数据网格中列标题的背景更改为带有白色文本的蓝色。 I was finally able to but the Mouse Over and Selection styles for the Column Header change the background to White. 我终于可以了,但是“列标题”的“鼠标悬停”和“选择”样式将背景更改为“白色”。 As you can imagine White text on a White Background won't do. 您可以想象,白色背景上的白色文本不会起作用。

For some reason this has been the most absurdly difficult thing to change. 由于某些原因,这是最荒唐的改变。

I tried using Styles: (had no effect) 我尝试使用样式:(无效)

<Style TargetType="{x:Type xcdg:ColumnManagerCell}">
            <Setter Property="SelectionBackground" Value="Black" />
            <Setter Property="Background" Value="#475463" />
            <Setter Property="FontWeight" Value="Bold" /> 
            <Setter Property="Foreground" Value="White" />
        </Style>

I tried doing it in the Grid itself (just throws an error) 我尝试在Grid本身中执行此操作(只是引发错误)

 <xcdg:DataGridControl ....
 <xcdg:ColumnManagerCell SelectionBackground="Black"></xcdg:ColumnManagerCell>

What magical incantation is required to perform the simple task of altering the hover background color on these cells??? 要执行更改这些单元格上的悬停背景颜色的简单任务,需要什么神奇的咒语???

Thanks 谢谢

The issue is that the Background is not handled by the ColumnManagerCell itself but a Border inside it. 问题是Background不是由ColumnManagerCell本身处理,而是由Border内部处理。

Reaching it is at best difficult so if your only concern is readability then just set the Foreground using a Trigger : 做到这一点最多是困难的,因此,如果您唯一关心的是可读性,则只需使用Trigger设置Foreground

<Style TargetType="xcdg:ColumnManagerCell">
    <Setter Property="Background" Value="#475463" />
    <Setter Property="FontWeight" Value="Bold" />
    <Setter Property="Foreground" Value="White" />
    <Style.Triggers>
        <Trigger Property="IsMouseOver" Value="True">
            <Setter Property="Foreground" Value="Black"></Setter>
        </Trigger>
    </Style.Triggers>
</Style>

You could also change the whole template , it's up to you to tell if it's worth the pain... 您还可以更改整个模板 ,这取决于您是否值得付出努力……

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM