title: WPF: Binding to validation rule's DependencyProperty
body: <p>I want to validate text box value against standard rules, and couple of them is Min and Max value. The problem is, that I need to have this values configurable (for example in settings file).</p>
  
  <p>I have validation rule:</p>
  
  <pre><code>public class TextBoxWithIntegerValidation : ValidationRule
      {
          private Int32RangeChecker _validRange;
  
          public Int32RangeChecker ValidRange
          {
              get { return _validRange; }
              set { _validRange = value; }
          }
  
          public override ValidationResult Validate(object value, CultureInfo cultureInfo)
          {
              var str = value as string;
              if (str == null)
              {
                  return new ValidationResult(false, Resources.TextResources.TextBoxIsEmpty_ErrorMessage);
              }
  
              int intValue = -1;
              if (!int.TryParse(str, out intValue))
              {
                  return new ValidationResult(false, Resources.TextResources.TextBoxNotIntegerValue_ErrorMessage);
              }
  
              if (intValue &lt; ValidRange.Minimum)
              {
                  return new ValidationResult(false, 
                      string.Format(Resources.TextResources.TextBoxValueLowerThanMin_ErrorMessage, ValidRange.Minimum));
              }
  
              return new ValidationResult(true, null);
          }
      }
  </code></pre>
  
  <p>Int range checker:</p>
  
  <pre><code> public class Int32RangeChecker : DependencyObject
  {
      public int Minimum
      {
          get { return (int)GetValue(MinimumProperty); }
          set { SetValue(MinimumProperty, value); }
      }
  
      public static readonly DependencyProperty MinimumProperty =
          DependencyProperty.Register("Minimum", typeof(int), typeof(Int32RangeChecker), new UIPropertyMetadata(0));
  
      public int Maximum
      {
          get { return (int)GetValue(MaximumProperty); }
          set { SetValue(MaximumProperty, value); }
      }
  
      public static readonly DependencyProperty MaximumProperty =
          DependencyProperty.Register("Maximum", typeof(int), typeof(Int32RangeChecker), new UIPropertyMetadata(100));
  
  }
  </code></pre>
  
  <p>And the text box validation:</p>
  
  <pre><code>&lt;TextBox&gt;
  &lt;TextBox.Text&gt;
      &lt;Binding Path="Interval" UpdateSourceTrigger="PropertyChanged" ValidatesOnNotifyDataErrors="True"&gt;
          &lt;Binding.ValidationRules&gt;
              &lt;validationRules:TextBoxWithIntegerValidation&gt;
                  &lt;validationRules:TextBoxWithIntegerValidation.ValidRange&gt;
                      &lt;validationRules:Int32RangeChecker
                              Minimum="{Binding IntervalMinValue}"
                          /&gt;
                  &lt;/validationRules:TextBoxWithIntegerValidation.ValidRange&gt;
              &lt;/validationRules:TextBoxWithIntegerValidation&gt;
          &lt;/Binding.ValidationRules&gt;
      &lt;/Binding&gt;
  &lt;/TextBox.Text&gt;
  </code></pre>
  
  <p></p>
  
  <p>TextBox placed inside the UserControl and appropriate ViemModel placed in the control DataContext.</p>
  
  <p>The problem is: property IntervalMinValue is not bound to the validation rule. If I set it manually - works fine, but not with the binding.</p>