Skip to main content
.NET 6.0+

ValidationModule.CustomizeApplicationRuntimeRules Event

Occurs when the ValidationModule.InitializeRuleSet method is invoked.

Namespace: DevExpress.ExpressApp.Validation

Assembly: DevExpress.ExpressApp.Validation.v24.1.dll

Declaration

public event EventHandler<CustomizeApplicationRuntimeRulesEventArgs> CustomizeApplicationRuntimeRules

Event Data

The CustomizeApplicationRuntimeRules event's data class is CustomizeApplicationRuntimeRulesEventArgs. The following properties provide information specific to this event:

Property Description
Application Specifies the object providing methods and properties to manage the current application. Inherited from CustomizeRulesEventArgs.
ApplicationModelRuleSet Specifies validation rules declared via the Application Model.
ObjectSpaceProvider Specifies the Object Space Provider to be used to create Object Spaces for creation of additional validation rules.
Rules Specifies additional validation rules to be used by the application. Inherited from CustomizeRulesEventArgs.
RuleSources Specifies additional validation rule sources to be used by the application. Inherited from CustomizeRulesEventArgs.

Remarks

Handle this event to create validation rules at run time. Add the required rules to the Rules collection. The following code snippet demonstrates how to create a validation rule at run time, ensuring that an end-user will not be able to save a Contact object unless its Anniversary property is specified.

using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Validation;
using DevExpress.Persistent.Validation;
//...
public sealed partial class MyModule : ModuleBase {
    ValidationModule validationModule;
    public MyModule() {
        InitializeComponent();
    }
    public override void Setup(ApplicationModulesManager moduleManager) {
        base.Setup(moduleManager);
        validationModule = moduleManager.Modules.FindModule<ValidationModule>();
        validationModule.CustomizeApplicationRuntimeRules += OnCustomizeRules;
    }
    void OnCustomizeRules(object sender, CustomizeApplicationRuntimeRulesEventArgs e) {
        RuleRequiredField myRule =
            new RuleRequiredField("myRule", 
            XafTypesInfo.Instance.FindTypeInfo(typeof(Contact)).FindMember("Anniversary"), 
            ContextIdentifier.Save);
        e.Rules.Add(myRule);
    }
}
See Also