title: How to Update DataGrid Cell Background when the Cell Value is Changed
body: <p>All, I have the following XAML to change the cells background colour at run-time based on whether the cells content is 'Help'. </p>
  
  <pre><code>&lt;UserControl.Resources&gt;
    &lt;local:CellColorConverter x:Key ="cellColorConverter"/&gt;
  &lt;/UserControl.Resources&gt;
  
     &lt;DataGrid x:Name="dataGrid" AlternatingRowBackground="Gainsboro" 
         AlternationCount="2" HorizontalAlignment="Stretch"
         VerticalAlignment="Stretch"&gt;
      &lt;DataGrid.CellStyle&gt;
         &lt;Style TargetType="DataGridCell" &gt;
            &lt;Setter Property="Background"&gt;
               &lt;Setter.Value&gt;
                  &lt;MultiBinding Converter="{StaticResource cellColorConverter}" &gt;
                     &lt;MultiBinding.Bindings&gt;
                        &lt;Binding RelativeSource="{RelativeSource Self}"/&gt;
                        &lt;Binding Path="Row"/&gt;
                     &lt;/MultiBinding.Bindings&gt;
                  &lt;/MultiBinding&gt;
               &lt;/Setter.Value&gt;
            &lt;/Setter&gt;
            &lt;Style.Triggers&gt;
               &lt;Trigger Property="IsSelected" Value="True"&gt;
                  &lt;Setter Property="Background" Value="#FF007ACC"/&gt;
                  &lt;Setter Property="Foreground" Value="White"/&gt;
               &lt;/Trigger&gt;
            &lt;/Style.Triggers&gt;
         &lt;/Style&gt;
      &lt;/DataGrid.CellStyle&gt;
  &lt;/DataGrid&gt;
  </code></pre>
  
  <p>The <code>CellColorConverter</code> class handle the 'converion'/colour update.</p>
  
  <pre><code>public class CellColorConverter : IMultiValueConverter
  {
      public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
      {
          if (values[1] is DataRow)
          {
              //Change the background of any cell with 1.0 to light red.
              var cell = (DataGridCell)values[0];
              var row = (DataRow)values[1];
              var columnName = cell.Column.SortMemberPath;
              if (row[columnName].ToString().CompareTo("Help") == 0)
                  return new SolidColorBrush(Colors.LightSalmon);
          }
          return SystemColors.AppWorkspaceColor;
      }
  
      public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
      {
       throw new System.NotImplementedException();
      }
  }
  </code></pre>
  
  <p>This works when the data is loaded in, but I also want the colour to be updated if the user types 'Help' into a cell. So I have tried amending the binding to </p>
  
  <pre><code>&lt;Setter Property="Background"&gt;
      &lt;Setter.Value&gt;
           &lt;MultiBinding Converter="{StaticResource cellColorConverter}" &gt;
                &lt;MultiBinding.Bindings&gt;
                     &lt;Binding RelativeSource="{RelativeSource Self}" // Changed this!
                              Mode="TwoWay" UpdateSourceTrigger="PropertyChanged"/&gt;
                     &lt;Binding Path="Row"/&gt;
                &lt;/MultiBinding.Bindings&gt;
           &lt;/MultiBinding&gt;
       &lt;/Setter.Value&gt;
  </code></pre>
  
  <p></p>
  
  <p>But this has not worked. <strong>How to I get the background cell colour to change when the cell value is changed and committed?</strong></p>
  
  <p>Thanks for your time.</p>