Did you tried using ValueConverter for this. Use dependency property to perform calculation based on previous value and this should trigger binding converter where you should set the color. For cell coloring using converter, refer to below code:
XAML:
<Window.Resources>
<local:NameToBrushConverter x:Key="CellConverter"/>
</Window.Resources>
...
<DataGridTextColumn Binding="{Binding PropertyName}">
<DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Background" Value="{Binding PropertyName, Converter={StaticResource NameToBrushConverter}}"/>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
Code:
public class CellConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
string input = value as string;
switch (input)
{
case <your value condition>:
return Brushes.Red;
default:
return DependencyProperty.UnsetValue;
}
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotSupportedException();
}
}