How do I enable text wrapping on all column headers?

Peter Todd picture Peter Todd · Aug 17, 2009 · Viewed 34.6k times · Source

How does one enable text wrapping on all column headers of a DataGrid, without disabling the other default header functionality? Such as column resizing, sort direction indicator, etc which are needed.

Is there a way to do this?

Answer

Nate picture Nate · Aug 25, 2011

Or don't bother with the primitives in the app.xaml file and do the following (my objects):

<DataGrid Name="WBdataGrid" AutoGenerateColumns="False" ColumnHeaderHeight="50" >
    <DataGrid.ColumnHeaderStyle>
        <Style TargetType="DataGridColumnHeader">
            <Setter Property="ContentTemplate">
                <Setter.Value>
                    <DataTemplate>
                        <TextBlock TextWrapping="Wrap" Text="{Binding}"></TextBlock>
                    </DataTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </DataGrid.ColumnHeaderStyle>
    <DataGrid.Columns> ...