5

I know how to define ValidationRules using nested elements (e.g. here) but how can I do it inline? I.e.

<TextBox Text="{Binding Amount, ValidationRules=???, Mode=TwoWay, ValidatesOnExceptions=True, NotifyOnValidationError=True}" >

I tried ValidationRules={StaticResource CashAmountRule} where CashAmountRule points to my custom validation rule class but the compiler complains it is not a Collection value. How can I make it one?

2 Answers2

2

It is not possible:

The following are properties of Binding that cannot be set using the Binding markup extension/{Binding} expression form.

  • [...]
  • ValidationRules: the property takes a generic collection of ValidationRule objects. This could be expressed as a property element in a Binding object element, but has no readily available attribute-parsing technique for usage in a Binding expression. See reference topic for ValidationRules.
  • [...]

Source

Otiel
  • 18,404
  • 16
  • 78
  • 126
-5

You need to implement ValidationRule in your model. Here's a link to get you started: Link

Community
  • 1
  • 1