如何更改 WPF 列表视图标题背景颜色

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34745758/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 13:37:24  来源:igfitidea点击:

How to Change WPF listview Header background color

wpfxaml

提问by Nafees Abbasi

enter image description here

在此处输入图片说明

How I can change remaining header background color in listview WPF C#.

如何在 listview WPF C# 中更改剩余的标题背景颜色。

回答by Julien

You can apply a style to GridViewColumnHeader

您可以将样式应用于 GridViewColumnHeader

For example :

例如 :

<Style x:Key="GridViewColumnHeaderStyle1" TargetType="{x:Type GridViewColumnHeader}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type GridViewColumnHeader}">
                <Border BorderThickness="0,0,0,1" BorderBrush="Black" Background="Transparent">
                    <TextBlock x:Name="ContentHeader" Text="{TemplateBinding Content}" Padding="5,5,5,0" Width="{TemplateBinding Width}" TextAlignment="Center" />
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
    <Setter Property="OverridesDefaultStyle" Value="True" />
    <Setter Property="Foreground" Value="Black" />
    <Setter Property="FontFamily" Value="Segoe UI" />
    <Setter Property="FontSize" Value="12" />
</Style>

and

<ListView VerticalAlignment="Bottom" Height="63" IsSynchronizedWithCurrentItem="True">
        <ListView.View>
            <GridView ColumnHeaderContainerStyle="{StaticResource GridViewColumnHeaderStyle1}" >
                <GridViewColumn/>
            </GridView>
        </ListView.View>
    </ListView>