Header wrap text and autoheight

16 posts, 1 answers
  1. rubenhak
    rubenhak avatar
    58 posts
    Member since:
    Dec 2008

    Posted 21 Sep 2009 Link to this post

    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.
  2. Answer
    Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 22 Sep 2009 Link to this post

    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.
  3. UI for WPF is Visual Studio 2017 Ready
  4. KodeKreachor
    KodeKreachor avatar
    18 posts
    Member since:
    Jan 2008

    Posted 30 Mar 2010 Link to this post

    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
  5. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 31 Mar 2010 Link to this post

    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.
  6. Afsal
    Afsal avatar
    24 posts
    Member since:
    Dec 2010

    Posted 05 Feb 2011 Link to this post

    I have similar issue in wpf. The grid headers are not wrapped. How can i fix that?
  7. Cloud
    Cloud avatar
    24 posts
    Member since:
    Oct 2008

    Posted 29 Nov 2011 Link to this post

    If I want to make the column header with text wraping as style and apply to all, what should I do?
  8. Vanya Pavlova
    Admin
    Vanya Pavlova avatar
    2019 posts

    Posted 29 Nov 2011 Link to this post

    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 >>

  9. Rebecca
    Rebecca avatar
    4 posts
    Member since:
    Jun 2013

    Posted 08 Oct 2013 Link to this post

    Sorry
  10. Rebecca
    Rebecca avatar
    4 posts
    Member since:
    Jun 2013

    Posted 08 Oct 2013 Link to this post

    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.
  11. Rebecca
    Rebecca avatar
    4 posts
    Member since:
    Jun 2013

    Posted 08 Oct 2013 Link to this post

    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?
  12. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 11 Oct 2013 Link to this post

    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 >>
  13. Jeff
    Jeff avatar
    25 posts
    Member since:
    Feb 2009

    Posted 03 Feb 2014 Link to this post

    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.
  14. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 05 Feb 2014 Link to this post

    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 >>
  15. Costa
    Costa avatar
    8 posts
    Member since:
    Mar 2014

    Posted 04 May 2014 in reply to KodeKreachor Link to this post

        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
  16. Timothy
    Timothy avatar
    3 posts
    Member since:
    Aug 2015

    Posted 08 Nov 2015 Link to this post

    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.
     
     
  17. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 10 Nov 2015 Link to this post

    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
Back to Top
UI for WPF is Visual Studio 2017 Ready