I have a datagrid which is a financial calculator with some cells that turn red on negative values. This is done via DataTrigger with converter. I also have overridden system highlight selection color. My problem now is that when I select a row the red cells don't get highlighted.

[Here's the picture](https://i.stack.imgur.com/F6hx9.png)

As far as I understand the custom cell style overrides selection. I want that my custom red cell be highlighted with 0.5 opacity blue bar just as well. How can I fix this?

Well, I can add an extra trigger to the cell style that changes BG color upon selection and tweak the color to fit, but that's rather a kludge. Or maybe I can implement an overlay color with opacity here somehow?

```
<Trigger Property="IsSelected" Value="True">
    <Setter Property="Background" Value="LightBlue" />
</Trigger>

```

Below is the full code. This is a stripped down, light weight but fully working example.

XAML

```
 <Window.Resources>
        <local:ValueToBoolConverter x:Key="ValueToBoolConverter"/>
    </Window.Resources>
    <Grid>
        <DataGrid ItemsSource="{Binding MainTable}"
                  AutoGenerateColumns="False"
                  CanUserAddRows="False">
            <DataGrid.RowStyle>
                <Style TargetType="DataGridRow">
                    <Setter Property="Background" Value="Azure"/>
                    <Style.Resources>
                        <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Blue" Opacity="0.5" />
                        <SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Black" />
                        <SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="Transparent" />
                    </Style.Resources>
                </Style>
            </DataGrid.RowStyle>
            <DataGrid.Columns>
                <DataGridTextColumn Header="Income Day" Binding="{Binding IncomeDay}" />
                <DataGridTextColumn Header="Income Week" Binding="{Binding IncomeWeek}">
                    <DataGridTextColumn.CellStyle>
                        <Style TargetType="DataGridCell">
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding IncomeWeek, Converter={StaticResource ValueToBoolConverter}}" Value="true">
                                    <Setter Property="Background" Value="Salmon"/>
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </DataGridTextColumn.CellStyle>
                </DataGridTextColumn>
                <DataGridTextColumn Header="Income Month" Binding="{Binding IncomeMonth}" />
                <DataGridTextColumn Header="Income Year" Binding="{Binding IncomeYear}" Width="*" />
            </DataGrid.Columns>
        </DataGrid>
    </Grid>

```

C#

```
using System;
using System.Collections.ObjectModel;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace Datagrid_Cell_Highlight
{
    public class TableData
    {
        public decimal IncomeDay { get; set; }
        public decimal IncomeWeek { get; set; }
        public decimal IncomeMonth { get; set; }
        public decimal IncomeYear { get; set; }
    }

    public class ViewModel
    {
        public ObservableCollection<TableData> MainTable { get; set; }
        public ViewModel()
        {
            MainTable = new ObservableCollection<TableData>
            {
                new TableData { IncomeDay = (decimal)1.11 },
                new TableData { IncomeDay = (decimal)2.22 },
                new TableData { IncomeDay = (decimal)-1.23 },
                new TableData { IncomeDay = (decimal)-2.34 }
            };
            foreach (var table in MainTable)
            {
                table.IncomeWeek = table.IncomeDay * 7;
                table.IncomeMonth = table.IncomeDay * 30;
                table.IncomeYear = table.IncomeDay * 365;
            }
        }
    }

    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            DataContext = new ViewModel();
        }
    }

    public class ValueToBoolConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if ((value is decimal) && ((decimal)value < 0))
                return true;
            else return false;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}

```