How to change the blue color of selected data rows

Ok, I saw this code for this:

<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> 

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

I would like to change the selected background of the string, which is blue by default, and I want a different color according to some conditions. For example, if a register is added, then if I select a row, it will be green; if this row is not selected, it will be light green.

I can change the color of the lines as I want, but when I select it, it will always be blue.

Thanks.

+4
source share
2 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" /> 
+14
source

for this you need to assign the color of the string programmatically

 <Setter Property="Background" Value="{Binding Path=BgColor}"/> 

Add the BgColor property to the object that is bound to the grid. In your state, set BgColor (i.e. if the object is registered, then BgColor is "green")

0
source

All Articles