Articles in this section
Category / Section

How to change the font size for header with ColumnSizer as SizeToHeader in WPF DataGrid (SfDataGrid)?

1 min read

The header text width is calculated with static font size in WPF DataGrid (SfDataGrid) and you can change the header font size using HeaderStyle property. You can achieve this by overriding GetFormattedText method in SfDataGrid.ColumnSizer class.

this.DataGrid.GridColumnSizer = new GridColumnSizerExt(DataGrid);public class GridColumnSizerExt : GridColumnSizer
{
 
    public GridColumnSizerExt(SfDataGrid dataGrid)
        : base(dataGrid)
    {
 
    }
 
    protected override FormattedText GetFormattedText(GridColumn column, object record, string displayText)
    {
        var formattedText = base.GetFormattedText(column, record, displayText);
 
        if (record == null)
        {
            formattedText.SetFontSize(16);
        }
        return formattedText;
    }
}

 
Image shows header text with Customized fontsize

View Sample in GitHub.

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied