Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the blue color of selected datagrid rows

Tags:

wpf

datagrid

Well, I have seen this code to do that:

<DataGrid.RowStyle>
    <Style TargetType="DataGridRow">

        <Style.Triggers>
            <Trigger Property="IsSelected" Value="True">
                <Setter Property="Background" Value="Black"/>
                <Setter Property="Foreground" Value="Green">
                </Setter>
            </Trigger>
        </Style.Triggers>

        <Setter Property="Background">                        
            <Setter.Value>
                <MultiBinding Converter="{StaticResource ucComponentesColorFilaMultiValueConverter}">
                    <Binding ElementName="dgdComponentes" Path="ItemsSource" />
                    <Binding ElementName="dgdComponentes" Path="SelectedItems" />
                    <Binding ElementName="CurrentItem" />
                </MultiBinding>
            </Setter.Value>
        </Setter>
    </Style>
</DataGrid.RowStyle>

Really the code is the style trigger, the setter property is for other cases, but I add the code of this can affect to the result.

I would like to change the selected row background, that by default is blue, and I want to other color according to some conditions. For example, if a register is added, then if I select the row it would be green, if this row is unselected, it would be light green.

I am be able to change the color of the rows as I want, but when I select it, always is blue.

Thanks.

like image 523
Álvaro García Avatar asked Dec 07 '22 13:12

Álvaro García


1 Answers

You can try something like this maybe...

       <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent" />
       <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent" />
like image 165
TMan Avatar answered Dec 11 '22 09:12

TMan