Word Wrap in a Column Header

Jul 31, 2009 at 4:25 PM

Is it possible to have word wrap in a column header?  I want to have my text split across 2 lines.

Thanks,

Tracy

Aug 4, 2009 at 10:22 AM

I also want to know how to do this.

Thanks,

Tony

Aug 5, 2009 at 1:16 AM

I found this could be accomplished by setting the Content Template for the DataGridColumnHeader.  

Here are two examples. In the first, I allow the word wrap to completly control the breaks. In the second, I force a break using two text blocks.

Regards,

Tracy

                <wpftoolkit:DataGridTextColumn Header="column 4- available - with word wrap for long content" 
                                               Width="*" 
                                               x:Name="Column4"
                                               Binding="{Binding Available}">
                    <wpftoolkit:DataGridTextColumn.HeaderStyle>

                            <Style  TargetType="{x:Type wpftoolkit:DataGridColumnHeader}">                                                
                            <Setter Property="ContentTemplate">
                                <Setter.Value>
                                    <DataTemplate>
                                        <TextBlock Text="{Binding}" TextWrapping="Wrap"  TextAlignment="Center"/>
                                    </DataTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </wpftoolkit:DataGridTextColumn.HeaderStyle>
                </wpftoolkit:DataGridTextColumn>

                <wpftoolkit:DataGridTextColumn Width="*" x:Name="Column5">
                    <wpftoolkit:DataGridTextColumn.HeaderStyle>
                        <Style  TargetType="{x:Type wpftoolkit:DataGridColumnHeader}">
                            <Setter Property="ContentTemplate">
                                <Setter.Value>
                                    <DataTemplate>
                                        <StackPanel>
                                        <TextBlock Text="column 5" TextWrapping="WrapWithOverflow"  TextAlignment="Center"/>
                                        <TextBlock Text="with a manual break as well as word wrap" TextWrapping="WrapWithOverflow"  TextAlignment="Center"/>
                                         </StackPanel>
                                    </DataTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </wpftoolkit:DataGridTextColumn.HeaderStyle>
                </wpftoolkit:DataGridTextColumn>