Search code examples
datagridwindows-community-toolkitwinui-3windows-app-sdk

WinUI3: How to style datagrid group header text?


I am using the Windows Community Toolkit DataGrid control in my WinUI3 project.

I would like to make the group header text bold. How can I do this?

Currently the group header looks like this (not bold):

group header, not bold

I have tried setting styles:

<ctWinUI:DataGrid ...>
    <ctWinUI:DataGrid.RowGroupHeaderStyles>
        <Style TargetType="ctWinUI:DataGridRowGroupHeader">
            <Setter Property="PropertyNameVisibility" Value="Collapsed"/>
            <Setter Property="ItemCountVisibility" Value="Collapsed"/>
            <Setter Property="FontWeight" Value="Bold"/>  <!--Ignored-->
        </Style>
        <Style TargetType="TextBlock">
            <Setter Property="FontWeight" Value="Bold"/>  <!--Ignored-->
        </Style>
    </ctWinUI:DataGrid.RowGroupHeaderStyles>
    ...
</ctWinUI:DataGrid>

Solution

  • You should be able to override the BodyTextBlockStyle theme resource:

    <ctWinUI:DataGrid.Resources>
        <Style x:Key="BodyTextBlockStyle" TargetType="TextBlock">
            <Setter Property="FontWeight" Value="Bold" />
        </Style>
    </ctWinUI:DataGrid.Resources>