• WPF DockLayoutManager布局后的布局重置


    初始化布局

                Logging.InfoBiz("初始化布局信息");
                dockLayoutManager = new DockLayoutManager();
                RestoreLayoutOptions.SetRemoveOldPanels(dockLayoutManager, false);
                RestoreLayoutOptions.SetAddNewPanels(dockLayoutManager, true);
                dockLayoutManager.DockingStyle = DockingStyle.VS2010;
                mainLayout.Children.Add(dockLayoutManager);

    保存默认布局

                // 保存默认布局
                dockLayoutManager.SaveLayoutToStream(defaultDockLayoutStream);
                defaultDockLayoutStream.Flush();

    恢复布局

                var layoutPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "layout.xml");
                if (File.Exists(layoutPath))
                {
                    dockLayoutManager.ClosedPanels.Clear();
                    dockLayoutManager.RestoreLayoutFromXml(layoutPath);
                    foreach (var panel in dockLayoutManager.ClosedPanels.ToList())
                    {
                        dockLayoutManager.DockController.Restore(panel);
                    }
                }

    1. 布局重置之前需要关闭活动区域

                var docPanel = (DocPanel)((IMainWindow)this).GetActiveDocPanel();
                if(docPanel!=null)
                {
                    dockLayoutManager.DockController.Close(docPanel);
                }

    2. 然后再恢复初始保存的布局

            protected void RestoreDefaultDockLayout()
            {
                var docPanel = (DocPanel)((IMainWindow)this).GetActiveDocPanel();
                if(docPanel!=null)
                {
                    dockLayoutManager.DockController.Close(docPanel);
                }
                
                defaultDockLayoutStream.Seek(0, SeekOrigin.Begin);
                dockLayoutManager.RestoreLayoutFromStream(defaultDockLayoutStream);
                foreach (var panel in dockLayoutManager.ClosedPanels.ToList())
                {
                    dockLayoutManager.DockController.Restore(panel);
                }
            }

    3. 将布局保存到配置文件

                var layoutPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "layout.xml");
                dockLayoutManager.SaveLayoutToXml(layoutPath);

    4. 切换布局中的活动区域

           private void OnWorkspacePanelCommandExecute(object obj)
            {
                BaseLayoutItem item = null;
                if (obj.Equals("1"))
                {
                    item = this.ermlPanel;
                }
                else if (obj.Equals("2"))
                {
                    item = this.serverPanel;
                }
                else if (obj.Equals("3"))
                {
                    item = this.diagramPanel;
                }
                else if (obj.Equals("4"))
                {
                    item = this.stdzPanel;
                }
                else if (obj.Equals("5"))
                {
                    item = this.outputPanel;
                }
                else if (obj.Equals("6"))
                {
                    item = this.reviewPanel;
                }
                else if (obj.Equals("7"))
                {
                    item = this.explrModelSearchPanel;
                }
                else if (obj.Equals("8"))
                {
                    item = this.naviPanel;
                }
    
                if (item.Visibility == Visibility.Visible)
                {
                    item.Visibility = Visibility.Collapsed;
                }
                else
                {
                    item.Visibility = Visibility.Visible;
                    dockLayoutManager.Activate(item);
                }
            }
  • 相关阅读:
    【Linux】- Systemd 命令篇
    【Linux】- 守护进程的启动方法
    【Linux】- CentOS安装docker及docker-compose
    【Python】- scrapy 爬取图片保存到本地、且返回保存路径
    解决百度ueditor支持iframe框架页面的视频播放问题
    php CURL 请求头和响应头获取
    phpcms pc标签 start不生效的原因
    单点登录的实现
    Linux下删除相互依赖的包
    如何通过js关闭微信浏览器页面
  • 原文地址:https://www.cnblogs.com/runningRain/p/13879025.html
Copyright © 2020-2023  润新知