Back to Devexpress

Implement Property Value Validation

expressappframework-402980-getting-started-in-depth-tutorial-blazor-enable-additional-modules-implement-property-value-validation.md

latest2.7 KB
Original Source

Implement Property Value Validation

  • Jun 26, 2025
  • 3 minutes to read

This lesson explains how to set validation rules for entity classes and their properties. XAF applies these rules when a user executes a specific operation (for example, saves an edited object).

The Validation System offers a number of predefined rule types and contexts. A rule specifies a data validity condition. A context defines the moment when the application checks the rule.

To use XAF Validation functionality, you need the DevExpress.ExpressApp.Validation.Blazor and DevExpress.ExpressApp.Validation.Win NuGet packages. When you created the solution and selected the Validation module in the project wizard, the wizard added these packages to platform-specific projects.

Tip

To add this functionality to an existing application, you need to install the NuGet packages and register the modules. For additional information, refer to the following section: Validation System Elements.

The instructions below explain how to do the following:

  • Use the Model Editor to prevent a user from marking a task as completed before the task starts (DemoTask.Status is NotStarted).
  • Create a rule in code that requires that the Position.Title property must not be empty.

Implement Property Value Validation in Model Editor

  1. Open the Model.DesignedDiffs.xafml file in the Model Editor. Navigate to the Validation | Rules node. Right-click the Rules node and select Add… | RuleCriteria.

  2. Set values of the following properties for the node:

  3. Navigate to the ActionDesign | Actions | DemoTask.MarkCompleted node and set the ValidationContexts property to MarkCompleted.

  4. Change the caption of the MarkCompleted Action to Mark Completed.

  5. Run the application and go to one of the unfinished tasks. Click the Mark Completed button. The following Validation Error dialog appears:

Implement Property Value Validation in Code

  1. Apply the RuleRequiredField attribute to the Title property in the Position class. Specify the context that triggers the rule (for example, DefaultContexts.Save) as the attribute’s parameter:

  2. Run the application and go to the Position List View.

Next Lesson

Highlight Property Editors

See Also

Validation (Prevent Data Errors)