title: validation on button click event wpf c#
body: <p>I have a WPF application where I have to check a <code>TextBox</code> value and a <code>ComboBox</code>. if it is empty or not on to the format the button click event should fire an error and if the selected index is 0 in the <code>ComboBox</code> again it should fire an error.(like in error provider).</p>
  
  <p>I did many research on the internet I came across with the solution with <em>IDataErrorInfo</em>. But the problem is how do i do this on the button click event. All of the examples are doing it on the form load.</p>
  
  <p>I'm quite new for WPF. following is my code </p>
  
  <pre><code>public class ClientMap : IDataErrorInfo
  {
      public string CDSNo { get; set; }
  
      public ClientMap(int ID)
      {
          Id = ID;
      }
      public ClientMap()
      {
  
      }
  
      public string Error
      {
          get { throw new NotImplementedException(); }
      }
  
      public string this[string columnName]
      {
          get
          {
              string result = null;
              if (columnName == "CDSNo")
              {
                  if (string.IsNullOrEmpty(CDSNo))
                      result = "Please enter a CDS No";
                  else
                  {
                      string regEx = "[A-Z]{3}-\\d{9}-[A-Z]{2}-\\d{2}";
                      if (!Regex.IsMatch(CDSNo, regEx))
                      {
                          result = "Invalid CDS No";
                      }
                  }
              }
  
              return result;
          }
      }
  
      public int Id { get; set; }
      public CE.Data.Customer Customer { get; set; }
      public CE.Data.Institute Institute { get; set; }
      public bool Archived { get; set; }
      public DateTime DateCreated { get; set; }
  
  }
  </code></pre>
  
  <p>and XAML is </p>
  
  <pre><code>&lt;Window.Resources&gt;
      &lt;validation:ClientMap x:Key="data"/&gt;
  &lt;/Window.Resources&gt;
  
  &lt;control:AutoCompleteTextBox Style="{StaticResource textBoxInError}"&gt;
      &lt;TextBox.Text&gt;
          &lt;Binding Path="CDSNo" Source="{StaticResource data}"
                  ValidatesOnDataErrors="True"   
                  UpdateSourceTrigger="Explicit"&gt;
  
              &lt;Binding.ValidationRules&gt;
                  &lt;ExceptionValidationRule/&gt;
              &lt;/Binding.ValidationRules&gt;
          &lt;/Binding&gt;
      &lt;/TextBox.Text&gt;
  &lt;/control:AutoCompleteTextBox&gt;
  </code></pre>
  
  <p>Please help me.
  Thanks</p>