Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change font size of a GridView's ColumnHeader

Is there an easy way to change header font size without overwriting completely duplicating ColumnHeaderTemplate?

Note: Not sure if it is relevant, but I use an application theme (PresentationFramework.Royale) which provides the ColumnHeaderTemplate.

like image 370
THX-1138 Avatar asked Dec 29 '22 22:12

THX-1138


1 Answers

If you aren't also applying a style to the Column Headers, you could use that. And even if you are, by setting the BasedOn property on the style you can maintain everything but what you want to change.

<ListView>
    <ListView.View>
        <GridView>
            <GridView.ColumnHeaderContainerStyle>
                <Style>
                    <Setter Property="TextElement.FontSize"
                            Value="32" />
                </Style>
            </GridView.ColumnHeaderContainerStyle>
            <GridViewColumn Header="Stuff"/>
            <GridViewColumn Header="More Stuff" />
        </GridView>
    </ListView.View>
</ListView>


Edit:
I Haven't used the built in themes before, so I tested this out. The PresentationFramework.Royale theme isn't actually applying a template to the column headers. It is applying a Style which uses a setter to apply the ControlTemplate like recommended.

So, in order to keep the Royale theme on the Column Headers we do need to use the BasedOn property of the Style we created. Here's the updated Style deffinition that will both allow you to modify what you like, and retain the Royale Theme:

<Style TargetType="{x:Type GridViewColumnHeader}" BasedOn="{StaticResource {x:Type GridViewColumnHeader}}">
like image 102
rmoore Avatar answered Jan 05 '23 19:01

rmoore