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

Header text wrapping defined in template

4 Answers 93 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Murray
Top achievements
Rank 2
Murray asked on 02 Jun 2012, 06:48 PM
Hi

I want to globally set header wrapping to wrap from the Resource template. I've come close but have an issue with the binding in the DataTemplate I've created for the ContentControl. Any help on correcting the path would be great

My current binding brings back the element name (I think?) System.Windows.Controls.TextBlock

<!--NewDataTemplate for text in ContentPresenter-->
    <DataTemplate x:Key="DataTemplate1">
        <TextBlock Text="{Binding Content, ElementName=ContentPresenter}" TextWrapping="Wrap"/>
    </DataTemplate>
 <!--End-->
    <ControlTemplate x:Key="GridViewHeaderCellTemplate" TargetType="grid:GridViewHeaderCell">
        <Grid x:Name="PART_HeaderCellGrid">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto"  />
            </Grid.ColumnDefinitions>
             
            <VisualStateManager.VisualStateGroups>
                <VisualStateGroup x:Name="CommonStates">
                    <VisualState x:Name="Normal" />
                    <VisualState x:Name="MouseOver">
                        <Storyboard>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="GridViewHeaderCell_Over" Storyboard.TargetProperty="Visibility">
                                <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                    <DiscreteObjectKeyFrame.Value>
                                        <Visibility>Visible</Visibility>
                                    </DiscreteObjectKeyFrame.Value>
                                </DiscreteObjectKeyFrame>
                            </ObjectAnimationUsingKeyFrames>
                        </Storyboard>
                    </VisualState>
                    <VisualState x:Name="Ascending">
                        <Storyboard>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Foreground">
                                <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource StrongBrush}"/>
                            </ObjectAnimationUsingKeyFrames>
                            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="PART_SortIndicator" Storyboard.TargetProperty="Opacity">
                                <DiscreteDoubleKeyFrame KeyTime="0:0:0" Value="1" />
                            </DoubleAnimationUsingKeyFrames>
                           <ObjectAnimationUsingKeyFrames Storyboard.TargetName="GridViewHeaderCell_Selected" Storyboard.TargetProperty="Visibility">
                                <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                    <DiscreteObjectKeyFrame.Value>
                                        <Visibility>Visible</Visibility>
                                    </DiscreteObjectKeyFrame.Value>
                                </DiscreteObjectKeyFrame>
                            </ObjectAnimationUsingKeyFrames>
                        </Storyboard>
                    </VisualState>
                    <VisualState x:Name="Descending">
                        <Storyboard>
                            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="PART_SortIndicator" Storyboard.TargetProperty="Opacity">
                                <DiscreteDoubleKeyFrame KeyTime="0:0:0" Value="1" />
                            </DoubleAnimationUsingKeyFrames>
                            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)" Storyboard.TargetName="PART_SortIndicator">
                                <EasingDoubleKeyFrame KeyTime="0:0:0" Value="180"/>
                            </DoubleAnimationUsingKeyFrames>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="GridViewHeaderCell_Selected" Storyboard.TargetProperty="Visibility">
                                <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                    <DiscreteObjectKeyFrame.Value>
                                        <Visibility>Visible</Visibility>
                                    </DiscreteObjectKeyFrame.Value>
                                </DiscreteObjectKeyFrame>
                            </ObjectAnimationUsingKeyFrames>
                        </Storyboard>
                    </VisualState>
                </VisualStateGroup>
            </VisualStateManager.VisualStateGroups>
             
 
            <Border x:Name="GridViewHeaderCell" Grid.ColumnSpan="2"
                    Background="{TemplateBinding Background}"
                    BorderBrush="{TemplateBinding BorderBrush}"
                    BorderThickness="{TemplateBinding BorderThickness}" />
 
            <Border x:Name="GridViewHeaderCell_Over" Opacity="0.1" Grid.ColumnSpan="2"  Background="{StaticResource StrongBrush}" BorderBrush="Transparent"  Visibility="Collapsed" />
 
            <Border x:Name="GridViewHeaderCell_Selected"  Grid.ColumnSpan="2" Margin="0,0,1,1" Background="{StaticResource BasicBrush}" BorderBrush="Transparent"   Visibility="Collapsed" />
 
 
            <ContentControl x:Name="ContentPresenter" Grid.Column="0" Foreground="{TemplateBinding Foreground}"
                            Style="{StaticResource StretchedContentControl}"
                            Margin="{TemplateBinding Padding}" IsTabStop="{TemplateBinding IsTabStop}"
                            Content="{TemplateBinding Content}" ContentTemplate="{StaticResource DataTemplate1}"
                            VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                            HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                            />

4 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 04 Jun 2012, 07:35 AM
Hello Murray,

That would be the expected behavior since the content of the header is of type object and in the basic case - it is a TextBlock. However, it could be anything that you define - TextBlock, TextBox, ComboBox, etc. That is why it return TextBlock in your scenario. You can try defining a style targeting TextBlock and set its TextWrapping property instead. 

All the best,
Maya
the Telerik team

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

0
Murray
Top achievements
Rank 2
answered on 04 Jun 2012, 11:18 AM
Thank you for the response Maya but maybe I didn't explain myself properly?

To rephrase, how do I allow the GridViewHeader to wrap text from the template as opposed to setting it every time in the implementation XAML?

Could I get a sample as Ive spent many hours trying to modify the template myself.
0
Murray
Top achievements
Rank 2
answered on 04 Jun 2012, 07:24 PM
Never mind Ive worked it out. Needed to define the ancestor and path to content.text
0
Nauman
Top achievements
Rank 1
answered on 11 Apr 2014, 06:42 AM
Was looking to do the same thing and tried lot of thing. Your method works the best.
Tags
GridView
Asked by
Murray
Top achievements
Rank 2
Answers by
Maya
Telerik team
Murray
Top achievements
Rank 2
Nauman
Top achievements
Rank 1
Share this question
or