title: ValidationRule vs Behavior in WPF
body: <p>Say I am trying to implement a piece of functionality in which a text box only allows integers to be inputted in by the user. I can implement this two ways, using a ValidationRule that checks whatever the user inputs and binding it to the text property through the XAML or I can create a new behavior and attach it to the control (not through binding).</p>
  
  <p>Examples of the XAML on both:</p>
  
  <p>Behavior:
  <code>&lt;TextBox behaviors:DigitsOnlyBehavior.IsDigitOnly="True"/&gt;</code></p>
  
  <p>ValidationRule which binds to the Window's Text property</p>
  
  <pre><code>&lt;TextBox&gt;
      &lt;TextBox.Text&gt;
          &lt;Binding RelativeSource = "{RelativeSource Mode=FindAncestor, AncestorType=Window}" Path="Text" UpdateSourceTrigger="PropertyChanged" Mode="TwoWay"&gt;
              &lt;Binding.ValidationRules&gt;
                  &lt;utils:RestrictInputTypeValidator Restriction="IntegersOnly" ValidatesOnTargetUpdated="True"/&gt;
              &lt;/Binding.ValidationRules&gt;
          &lt;/Binding&gt;
      &lt;/TextBox.Text&gt;
  &lt;/TextBox&gt;
  </code></pre>
  
  <p>What are the advantages and disadvantages of these approaches? When should I use them? Or is it a matter of preference?</p>