title: ValidationRules within control template
body: <p>I have control thats inherits from textbox</p>
  
  <pre><code>public class MyTextBox : TextBox
  </code></pre>
  
  <p>This has a style </p>
  
  <pre><code>&lt;Style TargetType="{x:Type Controls:MyTextBox}"&gt;
  </code></pre>
  
  <p>one of the Setters is </p>
  
  <pre><code>&lt;Setter Property="Template"&gt;
  </code></pre>
  
  <p>I want to be able to set the <code>Binding.ValidationRules</code> to something in the template, thus affecting all instances of this type of textbox. 
  I can therefore make textboxes for say Times, Dates, Numerics, post/zip codes.. or whatever i want, </p>
  
  <p>I don't want to have to set the validation rules every time i create a textbox. I just want to say i want a <code>NumericTextBox</code> and have it validate in whatever way is set in the template.</p>
  
  <p>Is this possible?</p>
  
  <p>All i have seen so far is the ValidationRules being set on each instance of the control e.g. </p>
  
  <pre><code>&lt;TextBox x:Name="txtEMail" Template={StaticResource TextBoxErrorTemplate}&gt;
  &lt;TextBox.Text&gt;
      &lt;Binding Path="EMail" UpdateSourceTrigger="PropertyChanged" &gt;
          &lt;Binding.ValidationRules&gt;
              &lt;local:RegexValidationRule Pattern="{StaticResource emailRegex}"/&gt;
          &lt;/Binding.ValidationRules&gt;
      &lt;/Binding&gt;
  &lt;/TextBox.Text&gt;
  </code></pre>
  
  <p>
  (from <a href="http://www.wpftutorial.net/DataValidation.html" rel="nofollow">http://www.wpftutorial.net/DataValidation.html</a>)</p>