dataGrid selected row color

Aug 10, 2009 at 4:40 PM

I use a trigger like this to set a brush for my selected row: 

<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="{StaticResource SelectBrush}"/>
</Trigger>

It kind of works, my row is still "standard blue" when selected and the selected cell have a black border. BUT If I scroll the grid horizontal I see my selectionbrush on barts of the row where there is no cells...

How shall I do? I want the hole selected row with my own Brush, and no borders on the selected cell.  I have SelectionMode="Single", and GridLinesVisibility="Horizontal"

Thanks!

Aug 10, 2009 at 6:20 PM

Ok, solved it with som Cell settings.

 

<

Style x:Key="MyCellStyle" TargetType="{x:Type my:DataGridCell}" >

 

<Setter Property="Background" Value="Transparent" />

 

<Setter Property="BorderBrush" Value="Transparent" />

 

<Setter Property="BorderThickness" Value="1" />

 

<Style.Triggers>

 

<MultiTrigger>

 

<MultiTrigger.Conditions>

 

<Condition Property="IsSelected" Value="True"/>

 

<Condition Property="IsKeyboardFocusWithin" Value="True"/>

 

</MultiTrigger.Conditions>

 

<Setter Property="Background" Value="{DynamicResource SelectBrush}" />

 

</MultiTrigger>

 

</Style.Triggers>

 

</Style>

Aug 17, 2009 at 5:06 PM

I am having the exact same problem but the cell settings did not fix it.

does anyone have any advice?

<Style TargetType="{x:Type dg:DataGridRow}">
        <Style.Triggers>
            <Trigger Property="IsSelected" Value="True">
                <Setter Property="Background" Value="Black" />
            </Trigger>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="Background" Value="{StaticResource LightBrush}" />
            </Trigger>
        </Style.Triggers>
    </Style>
    <Style TargetType="{x:Type dg:DataGridCell}">
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="BorderBrush" Value="Transparent" />
        <Style.Triggers>
            <Trigger Property="IsSelected" Value="True">
                <Setter Property="Background" Value="Black" />
            </Trigger>
        </Style.Triggers>
    </Style>
the IsMouseOver setter works, but the IsSelected doesn't
Mar 6, 2010 at 7:42 PM

There's a good article http://imduff.wordpress.com/2008/03/01/change-highlight-color-when-an-item-in-a-listview-is-selected/ about this issue.  Essentially, whatever color you choose is overriden by a brush with a specific name.  You need to replace that brush's declaration with one of your own, i.e.

<SolidColorBrush x:Key=”{x:Static SystemColors.HighlightBrushKey}” Color=”Green”/>


in the grid's resources.  That should change the selection color.

http://imduff.wordpress.com/2008/03/01/change-highlight-color-when-an-item-in-a-listview-is-selected/http://imduff.wordpress.com/2008/03/01/change-highlight-color-when-an-item-in-a-listview-is-selected/