Bind Font Size of HeaderCellStyle

2 posts, 0 answers
  1. Torsten
    Torsten avatar
    1 posts
    Member since:
    May 2014

    Posted 04 Dec 2015 Link to this post


    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ß







  2. Stefan
    Stefan avatar
    1073 posts

    Posted 09 Dec 2015 Link to this post

    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
Back to Top