• How to: Apply Application Model Changes to the Current View Immediately 如何:立即将应用程序模型更改应用于当前视图


    This topic describes how to implement Actions that make changes in the Application Model and then apply these changes to the current View without recreating it.

    本主题介绍如何在应用程序模型中实现更改的操作,然后将这些更改应用于当前视图而不重新创建它。

    Note 注意
    This solution does not apply to Mobile applications, because they do not support UI customization without recompilation.
    此解决方案不适用于移动应用程序,因为它们不支持 UI 自定义,而不重新编译。

    In the Action's SimpleAction.Execute event handler, save the Frame's View (Frame.View) object to a variable, and call the Frame.SetView method to detach the View from Frame. Pass null (Nothing in VB) as the view argument, and false as the disposeOldView argument to keep the detached view operational. After that, make changes to the Application model and call the View.LoadModel method with the false parameter. Next, use the SetView method's SetView(View view) overload to reattach the updated View to the Frame. The Controller below implements two Actions (SwitchMasterDetailMode and SwitchEditor) that illustrate this pattern.

    在操作的"简单操作.执行事件"处理程序中,将帧视图(Frame.View)对象保存到变量,然后调用 Frame.SetView 方法将视图从帧中分离出来。将 null(VB 中没有)作为视图参数,将 false 作为 disposeOldView 参数,以保持分离视图正常运行。之后,对应用程序模型进行更改,并调用 View.LoadModel 方法,方法是使用 false 参数。接下来,使用 SetView 方法的 SetView(视图视图)重载将更新的视图重新附加到框架。下面的控制器实现两个操作(切换主细节模式和切换编辑器),以说明此模式。

    using System;
    using DevExpress.ExpressApp;
    using DevExpress.ExpressApp.Actions;
    using DevExpress.ExpressApp.Scheduler.Win;
    using DevExpress.ExpressApp.Win.Editors;
    using DevExpress.Persistent.Base;
    using DevExpress.Persistent.Base.General;
    // ...
    public class RefreshViewControlsAfterModelChangesViewController : ObjectViewController<ListView, IEvent> {
        public RefreshViewControlsAfterModelChangesViewController() {
            new SimpleAction(this, "SwitchMasterDetailMode", PredefinedCategory.View.ToString(), (s, e) => {
                // Save the current View.
                ListView savedView = (ListView)Frame.View;
                // Detach the View from the Frame without disposing of it.
                if(Frame.SetView(null, true, null, false)) {
                    // Make required changes to the related Application Model nodes.
                    MasterDetailMode defaultMasterDetailMode = MasterDetailMode.ListViewOnly;
                    savedView.Model.MasterDetailMode = savedView.Model.MasterDetailMode == defaultMasterDetailMode ? MasterDetailMode.ListViewAndDetailView : defaultMasterDetailMode;
                    // Update the saved View according to the latest model changes and assign it back to the current Frame.
                    savedView.LoadModel(false);
                    Frame.SetView(savedView);
                }
            });
            new SimpleAction(this, "SwitchEditor", PredefinedCategory.View.ToString(), (s, e) => {
                var savedView = View;
                if(Frame.SetView(null, true, null, false)) {
                    Type defaultListEditorType = Application.Model.Views.DefaultListEditor;
                    savedView.Model.EditorType = savedView.Model.EditorType == defaultListEditorType ? typeof(SchedulerListEditor) : defaultListEditorType;
                    savedView.LoadModel(false);
                    Frame.SetView(savedView);
                }
            });
        }
    }
  • 相关阅读:
    ASP.NET程序中常用的三十三种代码[1]
    window.showModalDialog使用手册
    ASP函数详解
    ASP.NET程序中常用的三十三种代码[2]
    Session对象的清空
    Css不朽的经典—3D文字特效
    IIS6 ASP 0251超过响应缓冲区限制错误的解决方法
    ASP.NET程序中常用的三十三种代码[3]
    平面设计常用制作尺寸
    Work with a file upload and download controls2
  • 原文地址:https://www.cnblogs.com/foreachlife/p/How-to-Apply-Application-Model-Changes-to-the-Current-View-Immediately.html
Copyright © 2020-2023  润新知