title: Disable save button when validation fails
body: <p>As you can likely see from the title, I am about to ask something which has been asked many times before. But still, after reading all these other questions, I cannot find a decent solution to my problem.</p>
  
  <p>I have a model class with basic validation:</p>
  
  <pre><code>partial class Player : IDataErrorInfo
  {
      public bool CanSave { get; set; }
  
      public string this[string columnName]
      {
          get 
          { 
              string result = null;
              if (columnName == "Firstname")
              {
                  if (String.IsNullOrWhiteSpace(Firstname))
                  {
                      result = "Geef een voornaam in";
                  }
              }
              if (columnName == "Lastname")
              {
                  if (String.IsNullOrWhiteSpace(Lastname))
                  {
                      result = "Geef een familienaam in";
                  }
              }
              if (columnName == "Email")
              {
                  try
                  {
                      MailAddress email = new MailAddress(Email);
                  }
                  catch (FormatException)
                  {
                      result = "Geef een geldig e-mailadres in";
                  }
              }
              if (columnName == "Birthdate")
              {
                  if (Birthdate.Value.Date &gt;= DateTime.Now.Date)
                  {
                      result = "Geef een geldige geboortedatum in";
                  }
              }
  
              CanSave = true; // this line is wrong
              return result;
          }
      }
  
      public string Error { get { throw new NotImplementedException();} }
  }
  </code></pre>
  
  <p>This validation is done everytime the property changes (so everytime the user types a character in the textbox):</p>
  
  <pre><code>&lt;TextBox Text="{Binding CurrentPlayer.Firstname, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Top" Width="137" IsEnabled="{Binding Editing}" Grid.Row="1"/&gt;
  </code></pre>
  
  <p>This works perfect. The validation occurs (the <code>PropertyChanged</code> code for the binding is done in the VM on the CurrentPlayer property, which is an object of Player).</p>
  
  <p>What I would like to do now is disable the save button when the validation fails.</p>
  
  <p>First of all, the easiest solutions seems to be found in this thread:<br>
  <a href="https://stackoverflow.com/questions/6530529/enable-disable-save-button-during-validation-using-idataerrorinfo">Enable Disable save button during Validation using IDataErrorInfo</a></p>
  
  <ol>
  <li>If I want to follow the accepted solution, I'd have to write my
  validation code twice, as I cannot simply use the indexer. Writing
  double code is absolutely not what I want, so that's not a solution
  to my problem.</li>
  <li>The second answer on that thread sounded very promising as first,
  but the problem is that I have multiple fields that have to be
  validated. That way, everything relies on the last checked property
  (so if that field is filled in correctly, <code>CanSave</code> will be true, even
  though there are other fields which are still invalid).</li>
  </ol>
  
  <p>One more solution I've found is using an <code>ErrorCount</code> property. But as I'm validating at each property change (and so at each typed character), this isn't possible too - how could I know when to increase/decrease the <code>ErrorCount</code>?</p>
  
  <p>What would be the best way to solve this problem?</p>
  
  <p>Thanks</p>