ViewModelBase derives from
ModelBase, thus all information here also applies to the
Validation is very important for data objects. Therefore, the ModelBase supports all kinds of different validation:
- Internal validation via the ValidateFields and ValidateBusinessRules methods
- Validation via data annotations (attributes)
- External validators using the IValidatorProvider and IValidator interfaces
The validation results are cached and only executed when a property changes (the object becomes dirty) or when the validation is forced.
- Validation via validate methods
- Validation via data annotations
- Validation via special model validators
- Validation via IValidator
- Using the validation context
- Getting a summary of validation results
- Deferring validation
Different types of validation
There are two different types of validation in Catel, namely warnings and errors. There are also two flavors of validations, namely field validation and business rule validation.
Order of execution of events
The order of execution is very important if you want to perform very advanced validation (such as translating validations at the end of each validation sequence).
- OnValidation (raises Validating event) if not already validated
- OnValidatingFields (raises the ValidatingFields event)
- OnValidatedFields (raises the ValidatedFields event)
- OnValidatingBusinessRules (raises the ValidatingBusinessRules event)
- OnValidatedBusinessRules (raises the ValidatedBusinessRules event)
- IValidator.AfterValidateBusinessRules end if not already validated
- OnValidated (raises the Validated event)
There are lots of events, and it may seem complex and confusing at first sight. However, all these events give developers the opportunity to hook into the validation sequence at any time.
Have a question about Catel? Use StackOverflow with the Catel tag!