title: Change background of WPF DataGrid cell depending on value when populated with a datatable as IListSource
body: <p>I have seen similar posts like <a href="https://stackoverflow.com/questions/7381726/wpf-datagrid-row-background-based-on-cell-value">this</a></p>
  
  <p>However, they don't seem to answer my question. I have a XAML datagrid in a WPF application</p>
  
  <pre><code>&lt;DataGrid AutoGenerateColumns="True" Grid.Row="1" AlternationCount="2" HeadersVisibility="Column" Name="dgSkillsMatrix" Margin="0,0,0,1" HorizontalGridLinesBrush="White" VerticalGridLinesBrush="White" AlternatingRowBackground="#FFD0D0EB" RowBackground="#FFECECF5" FontSize="12"&gt;
      &lt;DataGrid.CellStyle&gt;
          &lt;Style TargetType="{x:Type DataGridCell}"&gt;
              &lt;Style.Triggers&gt;
                  &lt;DataTrigger Binding="{Binding Value}" Value="1"&gt;
                      &lt;Setter Property="Background" Value="Red"/&gt;
                  &lt;/DataTrigger&gt;
                  &lt;DataTrigger Binding="{Binding Content}" Value="2"&gt;
                      &lt;Setter Property="Background" Value="Green"/&gt;
                  &lt;/DataTrigger&gt;
                  &lt;DataTrigger Binding="{Binding Text}" Value="1"&gt;
                      &lt;Setter Property="Background" Value="Black"/&gt;
                  &lt;/DataTrigger&gt;
                  &lt;DataTrigger Binding="{Binding Name}" Value="Temp"&gt;
                      &lt;Setter Property="Background" Value="Black"/&gt;
                  &lt;/DataTrigger&gt;
              &lt;/Style.Triggers&gt;
          &lt;/Style&gt;
      &lt;/DataGrid.CellStyle&gt;
  &lt;/DataGrid&gt;
  </code></pre>
  
  <p>As you can see, I have tried a number of different ways to "Trigger" the colour change, but none of them fire. If I put a generic setting in abouve the triggers it will change the colour. </p>
  
  <p>I think the problem is that I am binding to the datagrid from a dynamic set of data that could change day to day, so I am using a datatable (below), as there is a varying number of coulmns that mean I can't use objects for each row, as I never know when the number of columns/properties would change.</p>
  
  <pre><code>this.dgSkillsMatrix.ItemsSource = (dt as IListSource).GetList();
  </code></pre>
  
  <p>I just need to know how to fire a trigger to change properties depending on that value of a cell created from a datatable to listsource.</p>