How to Set style for DataGrid header in WPF

后端 未结 2 668
轮回少年
轮回少年 2020-12-30 03:04

I have a DataGrid like this:



        
相关标签:
2条回答
  • 2020-12-30 03:35

    To avoid the effect of the header collapsing simply correct your style in this way:

      <Setter Property="HorizontalAlignment" Value="Stretch" />
      <Setter Property="HorizontalContentAlignment" Value="Center" />
    
    0 讨论(0)
  • 2020-12-30 03:48

    Adding the Style for DatagridColumnHeader of the Datagrid

    <DataGrid Name="GatewayPortsDataGrid" Height="auto" Width="auto">
         <DataGrid.Resources>
                <Style BasedOn="{StaticResource {x:Type DataGridColumnHeader}}" TargetType="{x:Type DataGridColumnHeader}" >
                <Setter Property="Background" Value="White" />
                <Setter Property="Foreground" Value="Black" />                                   
                <Setter Property="BorderBrush" Value="Black"/>                                  
                <Setter Property="BorderThickness" Value="1 1 1 1"/>                               
                <Setter Property="Margin" Value="-1,-1,0,0" />
                <Setter Property="Height" Value="28" />                                                                    
                <Setter Property="Width" Value="auto"/>                                    
                <Setter Property="HorizontalContentAlignment" Value="Center"/>                                                                        
                </Style>
            </DataGrid.Resources>
    </DataGrid>
    
    0 讨论(0)
提交回复
热议问题