Search code examples
c#wpfcoding-styledatagrid

Style datagrid table - Top left corner


I am styling a datatable but I can't figure out how to style the top left filed of the datagrid. It is the gray field in this picture:

enter image description here

Do you know how to do it?

Here is my style so far:

<Style TargetType="{x:Type DataGrid}">
    <Setter Property="Margin" Value="5" />
    <Setter Property="Background">
        <Setter.Value>
            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="White"/>
                <GradientStop Color="AliceBlue" Offset="1"/>
            </LinearGradientBrush>
        </Setter.Value>
    </Setter>
    <Setter Property="RowBackground">
        <Setter.Value>
            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="#BAF0FF"/>
                <GradientStop Color="PowderBlue" Offset="1"/>
            </LinearGradientBrush>
        </Setter.Value>
    </Setter>
    <Setter Property="AlternatingRowBackground">
        <Setter.Value>
            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="White"/>
                <GradientStop Color="AliceBlue" Offset="1"/>
            </LinearGradientBrush>
        </Setter.Value>
    </Setter>
    <Setter Property="HorizontalGridLinesBrush" Value="LightGray" />
    <Setter Property="VerticalGridLinesBrush" Value="LightGray" />
</Style>

Solution

  • From this answer I was able to create this code which correctly sets the style of the button:

    <DataGrid>    
        <DataGrid.Resources>
            <Style TargetType="Button" x:Key="{ComponentResourceKey ResourceId=DataGridSelectAllButtonStyle, TypeInTargetAssembly={x:Type DataGrid}}">
                <Setter Property="Background" Value="Black" />
            </Style>
        </DataGrid.Resources>
    </DataGrid>