The requested page is not available for the requested platform. You are viewing the content for Default platform.

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.

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.

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);
            }
        });
    }
}
See Also