<Window.Resources> <DataTemplate x:Key="BlueHeader"> <StackPanel Orientation="Horizontal" Margin="-5,-5,-5,-5" Width="120"> <StackPanel.Background> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FF223B84" Offset="1"/> <GradientStop Color="#FF57A0F4" Offset="0.5"/> <GradientStop Color="#FF4B94EC" Offset="0.5"/> </LinearGradientBrush> </StackPanel.Background> <TextBlock Margin="10,10,10,10" Text="{Binding}" VerticalAlignment="Center" Foreground="White"/> </StackPanel> </DataTemplate> </Window.Resources>
1. 修改GridView的ColumnHeaderTemplate,这是一个DataTemplate, 这种方式将对所有列的Header生效
<GridView ColumnHeaderTemplate="{StaticResource BlueHeader}">
2. 修改某一列的Header外观,同一个DataTemplate
<GridViewColumn Header="Code" DisplayMemberBinding="{Binding Path=Code}" HeaderTemplate="{StaticResource BlueHeader}" />
3. 直接编写某一列的Heade外观,不使用DataTemplate
<GridViewColumn> <GridViewColumn.Header> <GridViewColumnHeader> <Border> <TextBlock Text="表头"/> </Border> </GridViewColumnHeader> </GridViewColumn.Header> <GridViewColumn.CellTemplate> <DataTemplate> <Border> <TextBlock Text="{Binding xxx}"/> </Border> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn>
标签:外观,GridView,修改,表头,Header,DataTemplate From: https://www.cnblogs.com/lopengye/p/17918535.html