I need to align WPF DataGrid Column Header
text to Center. I created a style and attached that using the HeaderStyle
property as below.
Style
<Window.Resources>
<Style x:Key="CenterGridHeaderStyle" TargetType="DataGridColumnHeader">
<Setter Property="HorizontalContentAlignment" Value="Center"/>
</Style>
</Window.Resources>
Column
<DataGridTextColumn
Binding="{Binding Path=Name}" Header="Name" IsReadOnly="True"
HeaderStyle="{DynamicResource CenterGridHeaderStyle}"/>
But this does not align Column Header text to the Center. How can I do this?
Check this
It should be StaticResource instead of DynamicResource in the Column:
Style
Column
There is a response for doing it programmatically at AutoGeneratingColumn:
Tip, use attributes:
I landed here while searching for the same problem for Row Headers alignment. In case anyone else was searching, the solution is as simple as:
Try this
Here is what I am using to change the header text alignment.