Question: I have a method which comparing data in two dataTable. After comparing I´d like to visualizing these compared data (which are in new DataTable called ChangeTab) in WPF dataGRID. 

I´m filling datagrid from DataContext:

```
win.TableOfChange.DataContext = ChangeTab.DefaultView;

```

```xml
<DataGrid ItemsSource="{Binding}" Height="107" HorizontalAlignment="Left"....

```

I´m fighting with problem, how to visualize data which are different (in the DataTables) by red, and data which are the same with green color - similar like is in the picture:

![enter image description here](https://i.stack.imgur.com/4VZDZ.jpg)

Is there is a way, how to do that (Set colour to WPF dataGRID cell for some red and some green from C#)?

Thanks a lot!

Answer: 
I presume that you build the source table in the comparison process, if so you can easily store a boolean value that indicates equality. Then in the [`CellStyle`](http://msdn.microsoft.com/en-us/library/system.windows.controls.datagrid.cellstyle.aspx) you can use a [`DataTrigger`](http://msdn.microsoft.com/en-us/library/system.windows.datatrigger.aspx) on that property and have a [`Setter`](http://msdn.microsoft.com/en-us/library/system.windows.setter.aspx) change the [`TextElement.Foreground`](http://msdn.microsoft.com/en-us/library/system.windows.documents.textelement.foreground.aspx) property to the desired value.
I tend to use DataTemplates for most columns in the grid. You would need to create a class, something like this:

```
class CellContent
{
    public object Content { get; set; }
    public bool IsDifferent { get; set; }
}

```

Then create a datatemplate something like this:

```
<DataTemplate x:Key="bob">
    <ContentPresenter Content="{Binding Path=Content}" TextElement.Foreground="{Binding Path=IsDifferent, Converter={StaticResource myConverter}}" />
<DataTemplate>

```

You then assign the template to each column.

The other option which is probably better would be to use a Trigger to change the colour if the IsDifferent is true.