Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change background color of WPF DataGrid Top Left Corner Header

Tags:

wpf

datagrid

I am working on a Visual Studio extension and trying to theme a WPF DataGrid to match the Visual Studio light or dark theme. I have managed to get everything working except for the top left corner of the DataGrid.

DataGrid

In Silverlight, this is called the TopLeftCornerHeader, but I cannot figure out how to change the background color in WPF.

So far, I have modified the DataGrid like this,

<DataGrid 
    Background="{DynamicResource {x:Static wpf:Theme.BackgroundKey}}"
    Foreground="{DynamicResource {x:Static wpf:Theme.ForegroundKey}}"
    RowBackground="{DynamicResource {x:Static wpf:Theme.BackgroundKey}}"
    AlternatingRowBackground="{DynamicResource {x:Static wpf:Theme.BackgroundAccentKey}}" 
    HorizontalGridLinesBrush="{DynamicResource {x:Static wpf:Theme.ControlBorderKey}}"
    VerticalGridLinesBrush="{DynamicResource {x:Static wpf:Theme.ControlBorderKey}}"
    BorderBrush="{DynamicResource {x:Static wpf:Theme.ControlBorderKey}}" >
    <DataGrid.ColumnHeaderStyle>
        <Style TargetType="DataGridColumnHeader">
            <Setter Property="Background" Value="{DynamicResource {x:Static wpf:Theme.BackgroundKey}}" />
        </Style>
    </DataGrid.ColumnHeaderStyle>
like image 391
Rob Prouse Avatar asked Nov 11 '22 12:11

Rob Prouse


1 Answers

I think one of the only ways to be setting for DataGrid RowHeaderWidth:

<DataGrid x:Name="dataGrid"
          RowHeaderWidth="0" 
          ... />

I tried to set RowHeaderStyle and RowHeaderTemplate but they do not affect the area in the upper left corner.

It may also be PART_LeftHeaderGripper thumb which is located in DataGridColumnHeader, it is just to the left in the header column:

<Thumb x:Name="PART_LeftHeaderGripper"
       HorizontalAlignment="Left"
       Style="{StaticResource Style_HeaderGripper}" />
like image 190
Anatoliy Nikolaev Avatar answered Jan 04 '23 03:01

Anatoliy Nikolaev