Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MahApps DataGrid column header casing

I'm using the excellent MahApps library to style my WPF app and have integrated a DataGrid to display rows from a database. MahApps' default styling of the DataGrid displays the column headers in upper-case, but in my case I need to keep the original casing of the columns.

Now I'm not an expert in WPF and even less in WPF styling, so I was wondering whether there was an "easy" way to only reset the casing of the TextBlock used there, or if I had to re-define a complete DataGrid styling.

Thanks in advance, Thomas

like image 675
ThomasWeiss Avatar asked Oct 29 '15 02:10

ThomasWeiss


1 Answers

You can do this by creating a style just for the DataGridColumnHeader, not the whole DataGrid:

<Window xmlns:controls="http://metro.mahapps.com/winfx/xaml/controls"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        ... >


    <Window.Resources>
        <Style x:Key="MyColumnHeader" 
               BasedOn="{StaticResource MetroDataGridColumnHeader}" 
               TargetType="{x:Type DataGridColumnHeader}">
            <Setter Property="controls:ControlsHelper.ContentCharacterCasing" Value="Normal"/>
        </Style>
    </Window.Resources>

    ...

    <DataGrid ColumnHeaderStyle="{StaticResource MyColumnHeader}"
              ... />

    ...

</Window>

Make sure you have the latest (pre-release) version of MahApps (as of 29/10/2015)

like image 72
kkyr Avatar answered Nov 04 '22 14:11

kkyr