Any clue? The code below doesn't work properly...
Thank you!
<DataGrid AutoGenerateColumns="False" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Name="dg1" Grid.Row="0" >
<DataGridTemplateColumn Width="SizeToCells" IsReadOnly="True">
<DataGridTemplateColumn.HeaderTemplate>
<DataTemplate>
<Label HorizontalAlignment="Center" Content="First Name"></Label>
</DataTemplate>
</DataGridTemplateColumn.HeaderTemplate>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Label Content="{Binding FirstName}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
UPDATE:
Solution of @ArsenMkrt is great but I am facing some strange vertical lines...
Use HeaderStyle
instead of HeaderTemplate
<DataGridTemplateColumn.HeaderStyle>
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="HorizontalAlignment" Value="Center"/>
</Style>
</DataGridTemplateColumn.HeaderStyle>
try this It works for me to center the header without any issue.
<DataGridTemplateColumn.HeaderStyle>
<Style TargetType="DataGridColumnHeader">
<Setter Property="HorizontalContentAlignment" Value="Center"/>
</Style>
</DataGridTemplateColumn.HeaderStyle>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With