zoukankan      html  css  js  c++  java
  • 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);
                }
            }
  • 相关阅读:
    my first android test
    VVVVVVVVVV
    my first android test
    my first android test
    my first android test
    ini文件
    ZZZZ
    Standard Exception Classes in Python 1.5
    Python Module of the Week Python Module of the Week
    my first android test
  • 原文地址:https://www.cnblogs.com/runningRain/p/13879025.html
Copyright © 2011-2022 走看看