How To Change The Font Size For Header With Columnsizer As Sizetoheader In WPF Datagrid?

Sample date Updated on Jan 13, 2026
columnsizing datagrid header headertext wpf

This sample show cases how to change the fontsize for header with ColumnSizer as SizeToHeader in WPF DataGrid (SfDataGrid).

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

C

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;
    }
}

Changing the font size of the header with column sizer as SizeToHeader

Requirements to run the demo

Visual Studio 2015 and above versions

Up arrow