A newer version of this page is available. Switch to the current version.

Validation Contexts

  • 3 minutes to read

Validation Rules can be checked in the following Validation Contexts.

Standard Contexts:

  • Action

    XAF allows the use of Actions as Contexts. In this instance, a Rule is checked when executing a specified Action. To associate a context identifier with a particular Action, set it for the ValidationContexts property of the Application Model's ActionDesign | Actions | <Action> node. You can associate any number of context identifiers by listing them, separated by semicolons.

  • Save

    If you specify the DefaultContexts.Save Context for a Rule, this Rule will be checked each time the required object (or its properties) is saved to a database. Additionally, the in-place validation (see IModelValidationContext.AllowInplaceValidation) is enabled by default for this Context. To specify the Save Context in the Model Editor, set the IRuleBaseProperties.TargetContextIDs property to Save.

  • Delete

    With the DefaultContexts.Delete Context, a Rule is checked when deleting the required object. To specify the Delete Context in the Model Editor, set the IRuleBaseProperties.TargetContextIDs property to Delete.

Custom Contexts:

  • If the standard Contexts do not satisfy your requirements, you can implement custom Contexts. For details, refer to the Implement Custom Contexts topic.

When specifying a Context for a Rule, you can specify additional contextual criteria. In this instance, the Rule will be checked only if the property values of the validated object (or property) satisfy the specified criteria. For instance, the RuleRequiredField rule can be checked for the Birthday property if the Sex property is set to Sex.Female. To learn how to set this criteria, refer to the required Validation Rule attribute's TargetCriteria property description.


As the Validation system is designed to control user input, the system works automatically only for Views and Object Spaces assigned to them. So if you have manually instantiated a BaseObjectSpace and perform object modifications via this Object Space, the modifications are not validated. However, if you need to validate such modifications, you can do this by invoking the RuleSet.Validate method of a RuleSet object assigned to the static Validator.RuleSet property. For a detailed explanation, refer to the Implement Custom Contexts topic.

The Validation Module supplies the ShowAllContexts Action (it has the Validate caption in UI). This Action is activated for editable Detail Views and allows end-users to check predefined rules when editing data. When the ShowAllContexts Action is executed, all Validation Rules that are specified for the current object are checked in all associated contexts. Validation results are represented by the ContextValidationResult class in XAF. A pop-up window containing the ContextValidationResult List View is invoked if any broken Validation Rule is detected. All broken rules are detailed in this List View. To view more details on the validation results, double-click a grid item. The ContextValidationResult Detail View will be invoked.



The ContextValidationResult Detail View displays the DisplayableValidationResultItems collection. Each broken Validation Rule can be displayed via the DisplayableValidationResultItem Detail View, providing more details on validation results. This Detail View can be invoked by double-clicking a collection item.

Note that rules may have one of the following states: