Automatic input validation in WPF with data binding and Enterprise Library Validation Application Block

 

WPF provides validation infrastructure for databinding scenarios through ValidationRule objects. Only one built-in rule is provided, and you're expected to write most of these yourself. The way they work is by assigning one or more explicit rules to a binding:

<TextBox ...>
<TextBox.Text>
<Binding .>
<Binding.ValidationRules>
<local:JpgValidationRule/>
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
</TextBox>

[Example from Adam Nathan's excelent book on WPF]

Note that the syntax is much more involved than the simple non-validating binding:...

Read full article

No Comments