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

Bind Font Size of HeaderCellStyle

1 Answer 75 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 2
Torsten asked on 04 Dec 2015, 03:23 PM


I currently have a problem applying a bound size to the HeaderCellStyle.FontSize

Our operators have the possibility to set the text size to what they need.

I would like to have it bound like the FontSize for the GridCells in the following code snippet:


FontSize="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type lisaGridControl:LisaGridControl}}, Path=SettingsModel.GeneralSettings.FontSize, Mode=TwoWay}"



The proplem is that I can only find static solutions like:

<Style x:Key="GridHeaderCellStyle" TargetType="{x:Type telerik:GridViewHeaderCell}">
    <Setter Property="Foreground" Value="Black" />
    <Setter Property="FontSize" Value="16" />
    <Setter Property="FontWeight" Value="Normal" />
    <Setter Property="FontStyle" Value="Normal" />

Additionally my columns are created in code behind and I have no column definition in xaml.

For example the DisplayText for the header is bound as follows:

var bindingHeader = new Binding("DisplayText") { Source = column, ValidatesOnDataErrors = false, Mode = BindingMode.OneWay };
 if (column.GridColumn == null)
  throw new Exception("column.GridColumn(" + column.DisplayText + ")==null");
column.GridColumn.SetBinding(GridViewColumn.HeaderProperty, bindingHeader);

Thanks for any suggestions


Best regards


Thomas Voß







1 Answer, 1 is accepted

Sort by
Telerik team
answered on 09 Dec 2015, 11:24 AM
Hello Torsten,

In general, the DataContext of the column header is not the same as the DataContext of the column and needs to be set explicitly. For example, if you define an integer property named "FontSize" in your view model, you can set the Source property in the Binding of the header cell as follows.
<Style TargetType="telerik:GridViewHeaderCell">
    <Setter Property="FontSize"
            Value="{Binding FontSize, Source={StaticResource MyViewModel}}"/>

Stefan X1
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 Feedback Portal and vote to affect the priority of the items
Asked by
Top achievements
Rank 2
Answers by
Telerik team
Share this question