Header text wrapping defined in template

5 posts, 0 answers
  1. Murray
    Murray avatar
    121 posts
    Member since:
    Aug 2010

    Posted 02 Jun 2012 Link to this post

    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}"
                                />
  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 04 Jun 2012 Link to this post

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

  3. DevCraft banner
  4. Murray
    Murray avatar
    121 posts
    Member since:
    Aug 2010

    Posted 04 Jun 2012 Link to this post

    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.
  5. Murray
    Murray avatar
    121 posts
    Member since:
    Aug 2010

    Posted 04 Jun 2012 Link to this post

    Never mind Ive worked it out. Needed to define the ancestor and path to content.text
  6. Nauman
    Nauman avatar
    1 posts
    Member since:
    Apr 2014

    Posted 11 Apr 2014 Link to this post

    Was looking to do the same thing and tried lot of thing. Your method works the best.
Back to Top
DevCraft banner