<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> |
15 Answers, 1 is accepted
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.
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
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.
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 >>
You can check our online documentation on how to export a custom header.
Regards,Didie
Telerik
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 >>
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
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 >>
If e.Element = ExportElement.HeaderCell And TypeOf e.Value Is TextBlock Then
e.Value = DirectCast(e.Value, TextBlock).Text
End If
End Sub
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.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