title: WPF converter to update in real time background colour of textbox on text change
body: <p>I have two textboxes for the firstname and second name of a user and I have created a converter to change the background colour of the textbox when the text equals a specific string.  The problem I am having is that the textbox will only update at run time and doesn't update when I change the text is the textbox.</p>
  
  <p>XAML:</p>
  
  
  
  <pre><code>&lt;TextBox x:Name="forenameTextBox" Grid.Column="1" HorizontalAlignment="Left" Height="23" Margin="3" Grid.Row="1" 
                   Background="{Binding Staff,Converter ={StaticResource StaffNameToBackgroundColourConverter1}}"  
                   Text="{Binding Staff.Forename, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}" VerticalAlignment="Center" Width="120"/&gt;
  &lt;Label  Content="Surname:" Grid.Column="0" HorizontalAlignment="Left" Margin="3" Grid.Row="2" VerticalAlignment="Center"/&gt;
  &lt;TextBox x:Name="surnameTextBox" Grid.Column="1" HorizontalAlignment="Left" Height="23" Margin="3" Grid.Row="2"
                   Background="{Binding Staff,Converter={StaticResource StaffNameToBackgroundColourConverter1}}"  
                   Text="{Binding Staff.Surname, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}" VerticalAlignment="Center" Width="120"/&gt;
  </code></pre>
  
  <p>Converter code:</p>
  
  <pre class="lang-cs prettyprint-override"><code>public class StaffNameToBackgroundColourConverter : IValueConverter
  {
      public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
      {
          var staff  = (Staff) value;
          if (staff.Forename == "Donald" &amp;&amp; staff.Surname == "Duck")
          {
              return "Yellow";
          }
          else
          {
              return "White";
          }
      }
  
      public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
      {
          return value;
      }
  }
  </code></pre>
  
  <p>Correct text input:</p>
  
  <p><img src="https://i.stack.imgur.com/IWF8R.png" alt="Correct text input"></p>
  
  <p>Wrong text input - no change:</p>
  
  <p><img src="https://i.stack.imgur.com/mUjNA.png" alt="Wrong text input - no change"></p>