Bishan Bishan - 1 year ago 183
C# Question

Align DataGrid Column Header to Center

I need to align

WPF DataGrid Column Header
text to Center. I created a style and attached that using the
property as below.


<Style x:Key="CenterGridHeaderStyle" TargetType="DataGridColumnHeader">
<Setter Property="HorizontalContentAlignment" Value="Center"/>


Binding="{Binding Path=Name}" Header="Name" IsReadOnly="True"
HeaderStyle="{DynamicResource CenterGridHeaderStyle}"/>

But this is not align Column Header text to Center. How can i do this ?

Answer Source

Check this

<DataGridTextColumn Header="Nombre"
                          Binding="{Binding Nombre}">
  <Style TargetType="DataGridColumnHeader">
     <Setter Property="HorizontalContentAlignment"
                 Value="Center" />
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download