ValidationModule.CustomizeApplicationRuntimeRules Event

Occurs when the ValidationModule.InitializeRuleSet method is invoked.

Namespace: DevExpress.ExpressApp.Validation

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

Syntax

public event EventHandler<CustomizeApplicationRuntimeRulesEventArgs> CustomizeApplicationRuntimeRules

The event handler receives an argument of the CustomizeApplicationRuntimeRulesEventArgs type. The CustomizeApplicationRuntimeRulesEventArgs properties provide information specific to this event.

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(XafApplication application) {
        base.Setup(application);         
        validationModule = Application.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);
        validationModule.CustomizeApplicationRuntimeRules -= OnCustomizeRules;
        validationModule = null;
    }
}