tags:

views:

3623

answers:

4

This seems like a no-brainer but i just can't see how to do it.

The default background color of a selected row in DataGrid is so dark that I can't read it. Is there anyway of overriding it?

Tried this (modified from Neverminds link)

        <dg:DataGrid.RowStyle>
            <Style TargetType="{x:Type dg:DataGridRow}">
                <Style.Triggers>
                    <Trigger Property="IsSelected" Value="True" >
                        <Setter Property="Background" Value="Gainsboro" />
                    </Trigger>
                </Style.Triggers>
            </Style>
        </dg:DataGrid.RowStyle>

But still nothing...

A: 

Does this help?

http://blogs.msdn.com/jaimer/archive/2009/01/20/styling-microsoft-s-wpf-datagrid.aspx

Time Machine
not really, tried Style Trigger, but still nothing...
Jan Bannister
+9  A: 

Got it:

     <Style TargetType="{x:Type dg:DataGridCell}">
        <Style.Triggers>
            <Trigger Property="dg:DataGridCell.IsSelected" Value="True">
                <Setter Property="Background" Value="#CCDAFF" />
            </Trigger>
        </Style.Triggers>
    </Style>
Jan Bannister
This is great, I just ran into this and I was getting frustrated :-)
unforgiven3
+1  A: 

The above solution left blue border around each cell in my case.

This is the solution that worked for me. It is very simple, just add this to your DataGrid. You can change it from a SolidColorBrush to any other brush such as linear gradient.

<DataGrid.Resources> <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#FF0000"/></DataGrid.Resources>

Seb Kade
Nice hack! works quite well
TerrorAustralis
+1  A: 

The default IsSelected trigger changes 3 properties, Background, Foreground & BorderBrush. If you want to change the border as well as the background, just include this in your style trigger.

<Style TargetType="{x:Type dg:DataGridCell}">
    <Style.Triggers>
        <Trigger Property="dg:DataGridCell.IsSelected" Value="True">
            <Setter Property="Background" Value="#CCDAFF" />
            <Setter Property="BorderBrush" Value="Black" />
        </Trigger>
    </Style.Triggers>
</Style>
grantnz