This may (hopefully) have a trivial or very simple answer.
Suppose I want customized headings for my DataGrid
. I can use a DataTemplate
as
You can do it by binding TextBlock.Text
and you can do it either for all column headers in a DataGrid
by changing ContentTemplate
of header to be your custom TextBlock
and then just set Header
to text you want to display. It will also apply to automatically generated columns
<DataGrid ...>
<DataGrid.Resources>
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<TextBlock Text="{Binding}" TextWrapping="Wrap"/>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</DataGrid.Resources>
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Name}" Header="Header Text">
</DataGrid.Columns>
</DataGrid>
or can also do it per column just change TextBlock.Text
in you header template to use binding, as above
<TextBlock Text="{Binding}" TextWrapping="Wrap"/>
and then you column could look like this:
<DataGridTextColumn
Binding="{Binding Name}"
HeaderTemplate="{StaticResource ColumnHeaderTemplate}"
Header="Header Text"/>