Change the color of a grid header using Xceed Datagrid in WPF

◇◆丶佛笑我妖孽 提交于 2019-12-08 10:04:25

问题


I am using the Xceed data grid control and I am trying to change the header colors, but seem to be having some trouble. What I have right now is the following code snippet:

Style style = new Style(typeof(ColumnManagerRow));
style.Setters.Add(new Setter(ColumnManagerRow.BackgroundProperty, Brushes.Black));
this.grid.Resources[typeof(ColumnManagerRow)] = style;

This works for the most part, but I am still seeing some gray around it. Any help would be greatly appreciated.

EDIT

I've added an image with the selected areas that I'd like to have as the same color.


回答1:


You could do this in XAML:

<ControlTemplate x:Key="HeaderTemplate" TargetType="{x:Type xcdg:ColumnManagerCell}">
    <TextBlock Text="{TemplateBinding Content}">
        <TextBlock.Style>
            <Style TargetType="{x:Type TextBlock}">
                <Setter Property="Background" Value="Black" />
                <Setter Property="Foreground" Value="Red" />
            </Style>
        </TextBlock.Style>
    </TextBlock>
</ControlTemplate>

<Style TargetType="{x:Type xcdg:ColumnManagerRow}">
    <Setter Property="Background" Value="Black"/>
    <Setter Property="BorderBrush" Value="Black"/>
</Style>                

<Style TargetType="{x:Type xcdg:ColumnManagerCell}">
    <Setter Property="Template" Value="{StaticResource HeaderTemplate}"/>
</Style>


来源:https://stackoverflow.com/questions/13693619/change-the-color-of-a-grid-header-using-xceed-datagrid-in-wpf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!