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

Styling Cell Content to wrap text in SL3 Q1 2010

5 Answers 66 Views
GridView
This is a migrated thread and some comments may be shown as answers.
D V
Top achievements
Rank 1
D V asked on 23 Mar 2010, 04:25 PM

Prior to Q1 2010 version, I am able to modify the theme files ( Windows 7 theme)  and wrap the text content of cells automatically (i.e. TextWrapping is defaulted to Wrap rather than default value of NoWrap). However in Q1 2010 cell “TextWrapping” dependency property is marked obsolete. I understand that I can set “TextWrapping” dependency property in the markup but that is I am trying to avoid having to specify on “TextWrapping” on each GridViewDataColumn in the markup.  My User interface requirements are that text content be wrapped by default.  How do I style by column/cells in 2010 Q1 version to achieve same functionality?

 

Here is style declaration that used to work prior to 2010 Q1

 

    <Style

       

        TargetType="grid:GridViewCell">

        <Setter Property="Template" Value="{StaticResource GridViewCellTemplate}"/>

 

        <Setter Property="Padding" Value="5,0,3,0"/>

        <Setter Property="BorderBrush" Value="{StaticResource GridView_GridLinesItemBorder}"/>

            <Setter Property="BorderThickness" Value="0,0,1,0" />

        <!-- CHANGE Default to Top

        <Setter Property="VerticalContentAlignment" Value="Center" />

        -->

        <Setter Property="VerticalContentAlignment" Value="Top" />

        <Setter Property="HorizontalContentAlignment" Value="Stretch" />

            <Setter Property="Background" Value="Transparent" />

        <!-- CHANGE -->

        <Setter Property="TextWrapping" Value="Wrap" />

 

    </Style>

 

 

 

5 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 23 Mar 2010, 04:28 PM
Hello D V,

You can add TextBlock in the cell template add this property to this TextBlock.

Greetings,
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
D V
Top achievements
Rank 1
answered on 23 Mar 2010, 04:35 PM
Thanks for the reply. I understand that i can modify the control template ( or define a cell template) and add a text block. I have an existing SL3 application with 100+ pages and i am trying not having to change each of them individually. Is there a reason 2010 Q1 Themes are using ContentPresenter in Gridviewcell control template and not AlignmentContentPresenter.

From 2009 Q3 GridViewCell ControlTemplate

   <grid:AlignmentContentPresenter x:Name="PART_ContentPresenter" Margin="{TemplateBinding Padding}" Visibility="Visible"
           Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}"
           VerticalAlignment="{TemplateBinding VerticalContentAlignment}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
           TextAlignment="{TemplateBinding TextAlignment}" TextWrapping="{TemplateBinding TextWrapping}"
           TextDecorations="{TemplateBinding TextDecorations}"
            />

From 2010 Q1 GridViewCell ControlTemplate

 

 

<ContentPresenter x:Name="PART_ContentPresenter"

 

 

Margin="{TemplateBinding Padding}"

 

 

Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}"

 

 

VerticalAlignment="{TemplateBinding VerticalContentAlignment}"

 

 

HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" />

 


Thanks
Rao
0
Vlad
Telerik team
answered on 23 Mar 2010, 04:53 PM
Hi Rao,

AlignmentContentPresenter caused lots of bugs and performance problems and that why we decided to change this to lightweight version with TextBlock - now the grid will change only the Text property of the TextBlock instead of the cell Content which was slow.

According to your first post you already have defined Template in your style.

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
D V
Top achievements
Rank 1
answered on 23 Mar 2010, 06:00 PM
Well this used to work in SL2 a while back. There must be something wrong with my control template replacing contentpresenter with textblock. Please review and advice

<

 

ControlTemplate x:Key="GridViewCellTemplate" TargetType="grid:GridViewCell">

 

 

 

<Border x:Name="PART_CellBorder"

 

 

Background="{Binding Background, RelativeSource={RelativeSource TemplatedParent}}"

 

 

BorderBrush="{TemplateBinding VerticalGridLinesBrush}"

 

 

BorderThickness="{Binding VerticalGridLinesWidth, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource GridLineWidthToThicknessConverter}, ConverterParameter=Right}">

 

 

 

 

<vsm:VisualStateManager.VisualStateGroups>

 

 

 

<vsm:VisualStateGroup x:Name="CommonStates">

 

 

 

<vsm:VisualState x:Name="Normal" />

 

 

 

<vsm:VisualState x:Name="Current">

 

 

 

<Storyboard>

 

 

 

<ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_CellBorder" Storyboard.TargetProperty="Background">

 

 

 

<DiscreteObjectKeyFrame KeyTime="0:0:0" Value="{StaticResource GridView_CellBackground_Current}" />

 

 

 

</ObjectAnimationUsingKeyFrames>

 

 

 

</Storyboard>

 

 

 

</vsm:VisualState>

 

 

 

</vsm:VisualStateGroup>

 

 

 

<vsm:VisualStateGroup x:Name="EditingStates">

 

 

 

<vsm:VisualState x:Name="Edited">

 

 

 

<Storyboard>

 

 

 

<ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_ContentPresenter" Storyboard.TargetProperty="Margin">

 

 

 

<DiscreteObjectKeyFrame KeyTime="0:0:0" Value="0" />

 

 

 

</ObjectAnimationUsingKeyFrames>

 

 

 

<ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_ContentPresenter" Storyboard.TargetProperty="VerticalAlignment">

 

 

 

<DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Stretch" />

 

 

 

</ObjectAnimationUsingKeyFrames>

 

 

 

<ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_CellBorder" Storyboard.TargetProperty="Background">

 

 

 

<DiscreteObjectKeyFrame KeyTime="0:0:0" Value="{StaticResource GridView_CellBackground_Edited}" />

 

 

 

</ObjectAnimationUsingKeyFrames>

 

 

 

</Storyboard>

 

 

 

</vsm:VisualState>

 

 

 

<vsm:VisualState x:Name="Display" />

 

 

 

</vsm:VisualStateGroup>

 

 

 

<vsm:VisualStateGroup x:Name="DisabledStates">

 

 

 

<vsm:VisualState x:Name="Enabled" />

 

 

 

<vsm:VisualState x:Name="Disabled">

 

 

 

<Storyboard>

 

 

 

<ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_CellBorder" Storyboard.TargetProperty="Background">

 

 

 

<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource GridView_CellBackground_Disabled}" />

 

 

 

</ObjectAnimationUsingKeyFrames>

 

 

 

</Storyboard>

 

 

 

</vsm:VisualState>

 

 

 

</vsm:VisualStateGroup>

 

 

 

</vsm:VisualStateManager.VisualStateGroups>

 

 

 

 

<!--- CHANGE

 

<ContentPresenter x:Name="PART_ContentPresenter"

Margin="{TemplateBinding Padding}"

Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}"

VerticalAlignment="{TemplateBinding VerticalContentAlignment}"

HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" />

-->

 

 

<TextBlock x:Name="PART_ContentPresenter"

 

 

Margin="{TemplateBinding Padding}"

 

 

Text="{TemplateBinding Content}"

 

 

VerticalAlignment="{TemplateBinding VerticalContentAlignment}"

 

 

HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" TextWrapping="Wrap" />

 

 

 

</Border>

 

 

 

 

</ControlTemplate>

 

0
Vlad
Telerik team
answered on 25 Mar 2010, 05:09 PM
Hi,

Can you verify if you have set Width for this column? You can check the attache application for reference.

Kind regards,
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.
Tags
GridView
Asked by
D V
Top achievements
Rank 1
Answers by
Vlad
Telerik team
D V
Top achievements
Rank 1
Share this question
or