This is a migrated thread and some comments may be shown as answers.

Header wrap text and autoheight

15 Answers 629 Views
GridView
This is a migrated thread and some comments may be shown as answers.
rubenhak
Top achievements
Rank 1
rubenhak asked on 22 Sep 2009, 01:12 AM
Hi,

Is there a way to make the header row to wrap the header text and make it autosize to fit the full height? 
I achieved that by modifying the HeaderCellStyle of the column, but that solution replaces sorting/filtering/etc...
                        <telerik:GridViewDataColumn.HeaderCellStyle> 
                            <Style TargetType="{x:Type telerik:GridViewHeaderCell}"
                                <Setter Property="Template"
                                    <Setter.Value> 
                                        <ControlTemplate TargetType="{x:Type telerik:GridViewHeaderCell}"
                                            <TextBlock Text="{TemplateBinding Content}" TextWrapping="Wrap" VerticalAlignment="Center" Margin="2" /> 
                                        </ControlTemplate> 
                                    </Setter.Value> 
                                </Setter> 
                            </Style> 
                        </telerik:GridViewDataColumn.HeaderCellStyle> 

do you know a better way of doing that?

Thanks,
Ruben.

15 Answers, 1 is accepted

Sort by
1
Accepted
Rossen Hristov
Telerik team
answered on 22 Sep 2009, 10:15 AM
Hello rubenhak,

Recently we made the Header property of the column to accept objects, so you can place any UIElement in the header like this:

<UserControl x:Class="TicketID_244358_TextWrapForHeaderCell.MainPage" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"  
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"  
    xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView" 
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480"
    <Grid> 
        <telerik:RadGridView Name="clubsGrid" AutoGenerateColumns="False"
            <telerik:RadGridView.Columns> 
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}" Width="100"
                    <telerik:GridViewDataColumn.Header> 
                        <Grid> 
                            <TextBlock Text="This is some very long header that will be wrapped" 
                                       TextWrapping="Wrap"/> 
                        </Grid> 
                    </telerik:GridViewDataColumn.Header> 
                </telerik:GridViewDataColumn> 
            </telerik:RadGridView.Columns> 
        </telerik:RadGridView> 
    </Grid> 
</UserControl> 
 

Please find the sample project attached.

You will need to get the Latest Internal Build in case you are using an older version. I hope this helps.

Best wishes,
Ross
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
KodeKreachor
Top achievements
Rank 1
answered on 30 Mar 2010, 09:11 PM
Ross,
What will the column header text look like if you export that to Excel?
We're getting 'System.Windows.Controls.TextBlock' as the header text for each one that we've used a textblock in the header content template.

Eric
0
Vlad
Telerik team
answered on 31 Mar 2010, 07:34 AM
Hello Eric,

You can use the grid Exporting event to handle such cases - please check our demo for more info.

Sincerely yours,
Vlad
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Afsal
Top achievements
Rank 1
answered on 05 Feb 2011, 10:06 PM
I have similar issue in wpf. The grid headers are not wrapped. How can i fix that?
0
Cloud
Top achievements
Rank 1
answered on 29 Nov 2011, 02:17 PM
If I want to make the column header with text wraping as style and apply to all, what should I do?
0
Vanya Pavlova
Telerik team
answered on 29 Nov 2011, 02:56 PM
Hi Cloud,

 

Since you are manually defining the header for each column you may define a style targeted at TextBlock element and set the TextWrapping to Wrap. It will be respected by all text elements in the grid, including headers. Something like the following:


<UserControl.Resources>
        <Style TargetType="TextBlock">
            <Setter Property="TextWrapping" Value="Wrap"/>
            </Style>
        </UserControl.Resources>
    <Grid x:Name="LayoutRoot" Background="White" DataContext="{Binding Source={StaticResource SampleDataSource}}">
        <telerik:RadTreeListView GridLinesVisibility="None"  CanUserFreezeColumns="False" ShowInsertRow="True"  ItemsSource="{Binding Collection}">
            <telerik:RadTreeListView.Columns>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Property1}">
                    <telerik:GridViewDataColumn.Header>
                        <TextBlock Text="Wrapped Header"/>
                        </telerik:GridViewDataColumn.Header>
                    </telerik:GridViewDataColumn>
                </telerik:RadTreeListView.Columns>
            </telerik:RadTreeListView>
        




Regards,
Vanya Pavlova
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Rebecca
Top achievements
Rank 1
answered on 08 Oct 2013, 07:04 PM
Sorry
0
Rebecca
Top achievements
Rank 1
answered on 08 Oct 2013, 07:16 PM
Were you able to resolve this problem?  This is also happening for me.  If I set the header text in a textblock, I get "System.Windows.Controls.TextBlock" as the header text when I export to excel.
0
Rebecca
Top achievements
Rank 1
answered on 08 Oct 2013, 07:20 PM
If I set the header text in a textblock, I get "System.Windows.Controls.TextBlock" as the header text when I export to excel.  The example you showed defines the header text in the GridViewDataColumn with Header="something".  Unless I use something like a TextBox inside GridViewDataColumn.Header, I can't use wrapping in the header row.  So, how can I wrap the text in a header and have it show in the excel export with the header text I want?
0
Dimitrina
Telerik team
answered on 11 Oct 2013, 12:15 PM
Hi,

You can check our online documentation on how to  export a custom header.

Regards,
Didie
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Jeff
Top achievements
Rank 1
answered on 04 Feb 2014, 04:31 AM
I'm finding that the suggested implementation of specifying a TextBlock as the content of the Header property of a column counter to the implementation of the typical GridViewCustomPropertyProvider which is suggested for persistence of RadGridView user settings. Firstly column.Header.ToString() reduces the header down to it's full type name System.Windows.Controls.TextBlock upon serialization and this value is set back as the content of the header once again upon deserialization. Any advice on how to achieve both effectively without the unwanted side effects.
0
Dimitrina
Telerik team
answered on 05 Feb 2014, 05:18 PM
Hi,

Thank you for contacting us. I have already replied to the other forum post you have opened on the same topic here: http://www.telerik.com/community/forums/wrap-header-text


Regards,
Didie
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Costa
Top achievements
Rank 1
answered on 04 May 2014, 08:53 AM
    Private Sub gridview_ElementExporting(sender As Object, e As GridViewElementExportingEventArgs)
        If e.Element = ExportElement.HeaderCell And TypeOf e.Value Is TextBlock Then
            e.Value = DirectCast(e.Value, TextBlock).Text
        End If
    End Sub
0
Timothy
Top achievements
Rank 1
answered on 08 Nov 2015, 07:26 PM

This is getting ridiculous.  Simple scenarios like wrapping headers, custom cell backgrounds and exporting to Excel require hundreds of lines of "workaround" code.  I see almost zero real investment in the WPF components in recent years.  I think it's time to shop around.  The "support" we pay for every year simply points me to some demo that creates more work for me because the written documentation is so piss poor you didn't realize you weren't supposed to do it one way.  Demos are not documentation.

 To summarize the current instance, I have a column where I want to wrap the header text.  Original XAML:

<telerik:GridViewDataColumn Header="Region" DataMemberBinding="{Binding Path=Region}" />

New XAML:

<telerik:GridViewDataColumn DataMemberBinding="{Binding Path=Region}">

<telerik:GridViewDataColumn.Header>

<Grid>

<TextBlock Text="Region" TextWrapping="Wrap"/>

</Grid>

</telerik:GridViewDataColumn.Header>

</telerik:GridViewDataColumn>

​

This gets repeated for EVERY SINGLE COLUMN.  Now I want to export, so I have to cover that case with ANOTHER workaround. At what point does this tool decrease my productivity instead of increasing it? You're looking at it.
 
 
0
Maya
Telerik team
answered on 10 Nov 2015, 09:45 AM
Hi Timothy,

Indeed, you do have a valid point that this is a bit more work. We discussed the case and logged the item in our feedback portal. You can follow its progress directly from here - "Expose TextWrapping, TextAlignment, TextTrimming and TextDecorations properties for GridViewHeaderCell"


Regards,
Maya
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
GridView
Asked by
rubenhak
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
KodeKreachor
Top achievements
Rank 1
Vlad
Telerik team
Afsal
Top achievements
Rank 1
Cloud
Top achievements
Rank 1
Vanya Pavlova
Telerik team
Rebecca
Top achievements
Rank 1
Dimitrina
Telerik team
Jeff
Top achievements
Rank 1
Costa
Top achievements
Rank 1
Timothy
Top achievements
Rank 1
Maya
Telerik team
Share this question
or