How to: Disable an Action When the Current View Has Unsaved Changes 如何:当前视图具有未保存的更改时禁用按钮

This topic demonstrates how to disable an Action when business objects loaded to the current Object Space are changed. For this purpose, the IObjectSpace.ModifiedChanged event is handled, and the ActionBase.Enabled property is set based on the IObjectSpace.IsModified property.

本主题演示如何在加载到当前对象空间的业务对象发生更改时禁用操作。为此,将处理 IObjectSpace.修改更改事件,并根据 IObjectSpace.IsModified 属性设置"操作基础"。

Note 注意
The approach described in this topic is not supported by the Mobile platform. If it is necessary to implement this scenario in your Mobile application, contact us using the Support Center
移动平台不支持本主题中描述的方法。如果需要在移动应用程序中实施此方案,请使用支持中心与我们联系

.

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;
    }
}

As a result, the Action1 is grayed out in the UI when there are unsaved changes in the current View. It is impossible to execute the Action until changes are saved to a data store (e.g., using the Save Action). When the changes are saved, the Action1 reverts to its normal state.

因此,当当前视图中存在未保存的更改时,操作 1 在 UI 中显示为灰色。在将更改保存到数据存储(例如,使用保存操作)之前,无法执行操作。保存更改后,Action1 将恢复到其正常状态。

猜你喜欢

转载自www.cnblogs.com/foreachlife/p/How-to-Disable-an-Action-When-the-Current-View-Has-Unsaved-Changes.html