Rob Prouse
Rob Prouse

Reputation: 22657

Change background color of WPF DataGrid Top Left Corner Header

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>

Upvotes: 5

Views: 1936

Answers (2)

TheLostOne21
TheLostOne21

Reputation: 1

Setting my DataGridColumnHeader Margin to 0,0,0,0 resolved the issue

<Style TargetType="DataGridColumnHeader" x:Key="DataGridHeaderStyle">
    <Setter Property="Background" Value="#272537" />
    <Setter Property="Foreground" Value="AliceBlue" />
    <Setter Property="FontWeight" Value="Bold"/>
    <Setter Property="Margin" Value="0,0,0,0" />
</Style>

Upvotes: 0

Anatoliy Nikolaev
Anatoliy Nikolaev

Reputation: 22712

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}" />

Upvotes: 1

Related Questions