学习012-02-03-10 How to: Disable an Action When the Current View Has Unsaved Changes
Methods for Preventing an Action in the Active Window When There Are Unsaved Changes in It.
本主题展示如何在当前对象空间加载的业务对象发生更改时禁用动作。为此目的,在处理IObjectSpace_MODIFIED事件时会调整ActionBase.Enabled属性的值 该属性取决于IObjectSpace_ISMODIFIED的状态
C#
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using System;
// ...
public class ViewController1 : ViewController {
SimpleAction action1;
public ViewController1() {
action1 = new SimpleAction(this, "Action1", DevExpress.Persistent.Base.PredefinedCategory.View);
}
protected override void OnActivated() {
base.OnActivated();
ObjectSpace.ModifiedChanged += ObjectSpace_ModifiedChanged;
UpdateActionState();
}
void ObjectSpace_ModifiedChanged(object sender, EventArgs e) {
UpdateActionState();
}
protected virtual void UpdateActionState() {
action1.Enabled["ObjectSpaceIsModified"] = !ObjectSpace.IsModified;
}
protected override void OnDeactivated() {
base.OnDeactivated();
ObjectSpace.ModifiedChanged -= ObjectSpace_ModifiedChanged;
}
}
csharp

As a consequence, when unsaved changes exist in the current View, Action1 becomes disabled in the UI. The action cannot be executed until modifications are properly saved into a data store (for instance, by using Save Action). Once these adjustments have been made and saved into storage, however, it will revert back to its original state upon completion of saving.
Therefore, if there have been any pending edits or alterations that haven't yet been stored elsewhere within this platform's system, you'll need to ensure they're first stored before proceeding further with such actions.
