title: IDataErrorInfo : Not validating input
body: <p>I have a user control which contains a textbox. I have a class called Person which implements IDataErrorInfo interface:</p>
  
  <pre><code>class Person : IDataErrorInfo
  {
  private bool hasErrors = false;
  #region IDataErrorInfo Members
  
          public string Error
          {            
              get 
              {
                  string error = null;
                  if (hasErrors)
                  {
                      error = "xxThe form contains one or more validation errors";
                  }
                  return error;
              }
          }
  
          public string this[string columnName]
          {
              get 
              {
                  return DoValidation(columnName);
              }
          }
          #endregion
  }
  </code></pre>
  
  <p>Now the usercontrol exposes a method called SetSource through which the code sets the binding:</p>
  
  <pre><code>public partial class TxtUserControl : UserControl 
      {          
          private Binding _binding;
  
          public void SetSource(string path,Object source)
          {
              _binding = new Binding(path);
              _binding.Source = source;
              ValidationRule rule;
              rule = new DataErrorValidationRule();
              rule.ValidatesOnTargetUpdated = true;            
              _binding.ValidationRules.Add(rule);
              _binding.ValidatesOnDataErrors = true;
              _binding.UpdateSourceTrigger = UpdateSourceTrigger.LostFocus;
              _binding.NotifyOnValidationError = true;            
              _binding.ValidatesOnExceptions = true;
              txtNumeric.SetBinding(TextBox.TextProperty, _binding);                
          }
  ...
  }
  </code></pre>
  
  <p>The WPF window that includes the user control has the following code:</p>
  
  <pre><code>public SampleWindow()
      {
          person= new Person();
          person.Age = new Age();
          person.Age.Value = 28;
  
          numericAdmins.SetSource("Age.Value", person);
      }
      private void btnOk_Click(object sender, RoutedEventArgs e)
      {         
  
          if(!String.IsNullOrEmpty(person.Error))
          {
              MessageBox.Show("Error: "+person.Error);
          }
      }
  </code></pre>
  
  <p>Given this code, the binding is working fine, but the validation never gets triggered. Whats wrong with this code?</p>