title: Accessing Validation Errors in a UserControl
body: <p>I created a WPF (.Net 4) UserControl containing some ComboBoxes and a TextBox. In XAML, some ValidationRules are bound to the TextBox. If the TextBox contains invalid data, a red frame is shown, and the tooltip is set to the error description. Works well.</p>
  
  <p>Next, I placed two instances of that UserControl on a form, and added a button. In XAML, the button is connected to a RelayCommand of the ViewModel. Now I want the button to be enabled only when both of the UserControls contain valid data only.</p>
  
  <p>Not a problem, I thought, let me use a strategy which works elsewhere. I added a trigger:</p>
  
  <pre><code>    &lt;Button Content="_OK" ... Command="{Binding Path=OKCommand}"&gt;
          &lt;Button.Style&gt;
              &lt;Style TargetType="{x:Type Button}"&gt;
                  &lt;Setter Property="IsEnabled" Value="false" /&gt;
                  &lt;Style.Triggers&gt;
                      &lt;MultiDataTrigger&gt;
                          &lt;MultiDataTrigger.Conditions&gt;
                              &lt;Condition Binding="{Binding ElementName=cascadingComboFrom, Path=(Validation.HasError)}" Value="false" /&gt;
                              &lt;Condition Binding="{Binding ElementName=cascadingComboTo, Path=(Validation.HasError)}" Value="false" /&gt;
                          &lt;/MultiDataTrigger.Conditions&gt;
                          &lt;Setter Property="IsEnabled" Value="true" /&gt;
                      &lt;/MultiDataTrigger&gt;
                  &lt;/Style.Triggers&gt;
              &lt;/Style&gt;
          &lt;/Button.Style&gt;
      &lt;/Button&gt;
  </code></pre>
  
  <p>But there is a catch: Validation.HasError is always false for the UserControls - the Validation failed for an element inside the UserControl, not for the UserControl proper.</p>
  
  <p>I know that I can register the Click event of the button, check the validity there using the method shown in <a href="https://stackoverflow.com/questions/127477/detecting-wpf-validation-errors">Detecting WPF Validation Errors</a>, and prevent the execution of the RelayCommand by setting the Handled property of the RoutedEventArgs to true. But that looks more like WTF than WPF.</p>
  
  <p>What do you suggest? How can I retrieve the Validation Errors of the UserControl's children? Or how can I get them in the RelayCommand's CanExecute method? Or some other tricks?</p>