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

Dynamic GridViewCell Font size

3 Answers 92 Views
GridView
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 04 May 2011, 02:27 AM
We are trying to provide a feature to our users that will let them dynamically change the font size of the cells.
We have 3 radio buttons that let them select the size they would like (normal, small, extra small).

The suggested way I found on this forum was to use a style to set the font size. However styles can not be changed after being created, so we tried creating 3 styles and switching dynamically between them

<Style TargetType="telerik:GridViewCell" x:Key="cellFontSizeNormal" >
    <Setter Property="FontSize" Value="25" />
</Style>
<Style TargetType="telerik:GridViewCell" x:Key="cellFontSizeSmall" >
    <Setter Property="FontSize" Value="18" />
</Style>
....

switch (size)
{
    case "Normal":
        cellStyle = this.Resources["cellFontSizeNormal"] as Style;
        break;
    case "Small":
        cellStyle = this.Resources["cellFontSizeSmall"] as Style;
        break;
    case "ExtraSmall":
        cellStyle = this.Resources["cellFontSizeExtraSmall"] as Style;
        break;
}
 
foreach (var column in MyGrid.Columns)
{
    column.CellStyle = cellStyle;   
}

The problem is that the grid does not refresh itself after the new style has been applied. We have turned off column virtualization but that did not effect anything.
Is there a way to refresh the grid after our styles have changed, or is there a better way to dynamically change the font size of the cells?

3 Answers, 1 is accepted

Sort by
0
Accepted
Dimitrina
Telerik team
answered on 04 May 2011, 04:23 PM
Hi David,

 If you would like to apply a selected style to all the cells in the RadGridView, you should apply it to the GridView object. Then the same style will be applied to all its child objects. 

You could as well set the FontSize property of the GridView directly (without using any style).

For example:

<Style TargetType="telerik:RadGridView" x:Key="cellFontSizeSmall" >
    <Setter Property="FontSize" Value="18" />
</Style>
this.playersGrid.Style = this.Resources["cellFontSizeSmall"] as Style;
 
or
 
this.playersGrid.FontSize = 18;

Does this meet your requirements?

Regards,
Didie
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
David
Top achievements
Rank 1
answered on 06 May 2011, 04:01 AM
That does work, but it also changes the size of the headings. I was trying to just set the fontsize of the cells.
0
Dimitrina
Telerik team
answered on 09 May 2011, 09:31 AM
Hi David,

 The way to refresh the RadGridView after the column styles have changed is with a call to .Rebind(); The CellStyle is defined independently for each column, so basically the way to apply styles is the one that you have implemented, plus rebinding of the grid.

If you prefer you could make this functionality to be MVVM friendly by encapsulating it using a Behavior . You could use this behavior everywhere after that. 

I am attaching a sample project showing how the GridViewCell Font size is set with a Behavior.

All the best,
Didie
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
David
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
David
Top achievements
Rank 1
Share this question
or