1

I created a class IntegersValidationRule which inherits from ValidationRule. Now I don't know what code should I write in XAML. That's what I have:

<TextBox Name="defaultTxt"
     Height="23" Width="200">
  <TextBox.Text>
    <Binding UpdateSourceTrigger="PropertyChanged">
      <Binding.ValidationRules>
        <what:IntegersValidationRule/>
      </Binding.ValidationRules>
    </Binding>
  </TextBox.Text>
</TextBox>

I know that either I'm so stupid that I can't understand in many tutorials what Path in Binding property means, why should we use Binding here when there's no binding required and what should I use instead of 'what' word inside Binding.ValidationRule.

H.B.
  • 166,899
  • 29
  • 327
  • 400
Sergey
  • 11,548
  • 24
  • 76
  • 113

2 Answers2

2

what is an xmlns (see MSDN) which needs to point to the namespace in which your validation rule class is declared, e.g.

xmlns:what="clr-namespace:MyApp.MyValidationRules"

If you add no Path (- how about reading this if you do not understand it? -) the binding will bind to the current DataContext, whatever that may be in your case.

H.B.
  • 166,899
  • 29
  • 327
  • 400
1
  • Question 1: validators work on bindings. That is why you specify the rule on a binding. As soon as then value will be updated to the source (object that the control binds to) the rule is checked.

  • Question 2: See H.B. 's answer

Emond
  • 50,210
  • 11
  • 84
  • 115