Validation in MVVM-based applications
As mentioned in the introduction to this chapter, we have a lot of validation options to choose from in XAML-based technologies. Let's now take a look at the options that are best suited for use in MVVM applications.
Validation rules
This is the simplest and most commonly used validation technique. A WPF binding can be associated with a number of custom validation rules, each subclassed from ValidationRule
. There are only two validation rules provided as part of the library: DataErrorValidationRule
and ExceptionValidationRule
.
Using validation rules
We can define additional custom validation rules by inheriting from ValidationRule
. We can add them to the ValidationRules
collection for a binding, as follows: ...
Get MVVM Survival Guide for Enterprise Architectures in Silverlight and WPF now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.