title: WPF form validation before source update using IDataErrorInfo
body: <p>I'm trying to implement elegant form validation in a C# / WPF / Entity Framework 4.0 application. I have a classic form (some textboxes and checkboxes) and a save button.<br>
  I only want to update the source (and database) when the user presses save, and I also only want to run the form validation when the user presses save.</p>
  
  <p>I set all my bindings with the parameter <code>UpdateSourceTrigger=Explicit</code>. I also placed all the bindings within a <code>BindingGroup</code>.</p>
  
  <p>When the user presses save I trigger the <code>UpdateSources</code> method of the binding group - this triggers <code>UpdateSource</code> on each binding. At this point (<strong>before the source update completes</strong>) I want the form validation to take place and errors to be highlighted in the GUI. If there are no input errors then the update should be free to go through.</p>
  
  <p>I thought I could achieve this by implementing <code>IDataErrorInfo</code> on the <code>EntityObject</code> the fields are bound to, and setting the parameter <code>ValidatesOnDataErrors=True</code> on all my bindings.</p>
  
  <p>Unfortunately this does <em>not</em> work because as explained here:
  <a href="http://msdn.microsoft.com/en-us/library/ms752347.aspx#data_validation" rel="noreferrer">MSDN Databinding Overview - Data Validation</a>
  under the heading "Validation Process" </p>
  
  <blockquote>
    <p>5) The binding engine sets the source property.</p>
    
    <p>6) ...... This is the point when bindings that have the ValidatesOnDataErrors set to true are checked. </p>
  </blockquote>
  
  <p>This seems really stupid to me - why would you want to validate the data after it has already been "committed" to the object? I've been searching for hours for a way to get the behavior I want... Has someone done something like this before?</p>
  
  <p>So the main question is:<br>
  <strong>How can I validate the input BEFORE the source is updated and cancel the update if the validation fails?</strong></p>