DockPanel Suite DockContent全部出现在DockPanel的左上角

时间:2016-02-03 00:43:27

标签: c# xml winforms dockpanel-suite

enter image description here有时当我的程序启动时,它无法将DockPanel DockContent放在配置文件中指定的正确位置。

配置文件如下所示:

<?xml version="1.0" encoding="utf-16"?>
<!--DockPanel configuration file. Author: Weifen Luo, all rights reserved.-->
<!--!!! AUTOMATICALLY GENERATED FILE. DO NOT MODIFY !!!-->
<DockPanel FormatVersion="1.0" DockLeftPortion="0.25" DockRightPortion="0.25" DockTopPortion="0.25" DockBottomPortion="0.25" ActiveDocumentPane="-1" ActivePane="-1">
  <Contents Count="5">
    <Content ID="0" PersistString="Imogen3.Forms.Dockable.FrmLogging" AutoHidePortion="0.25" IsHidden="False" IsFloat="False" />
    <Content ID="1" PersistString="Imogen3.Forms.Dockable.FrmTimers" AutoHidePortion="0.25" IsHidden="False" IsFloat="False" />
    <Content ID="2" PersistString="Imogen3.Forms.Dockable.FrmImageAssessmentControl" AutoHidePortion="0.25" IsHidden="False" IsFloat="False" />
    <Content ID="3" PersistString="Imogen3.Forms.Dockable.FrmRestrictedBrowser" AutoHidePortion="0.25" IsHidden="False" IsFloat="False" />
    <Content ID="4" PersistString="Imogen3.Forms.Dockable.FrmGroupCandidates" AutoHidePortion="0.25" IsHidden="False" IsFloat="False" />
  </Contents>
  <Panes Count="3">
    <Pane ID="0" DockState="DockBottom" ActiveContent="0">
      <Contents Count="1">
        <Content ID="0" RefID="0" />
      </Contents>
    </Pane>
    <Pane ID="1" DockState="DockBottom" ActiveContent="1">
      <Contents Count="1">
        <Content ID="0" RefID="1" />
      </Contents>
    </Pane>
    <Pane ID="2" DockState="Document" ActiveContent="2">
      <Contents Count="3">
        <Content ID="0" RefID="2" />
        <Content ID="1" RefID="3" />
        <Content ID="2" RefID="4" />
      </Contents>
    </Pane>
  </Panes>
  <DockWindows>
    <DockWindow ID="0" DockState="Document" ZOrderIndex="1">
      <NestedPanes Count="1">
        <Pane ID="0" RefID="2" PrevPane="-1" Alignment="Right" Proportion="0.5" />
      </NestedPanes>
    </DockWindow>
    <DockWindow ID="1" DockState="DockLeft" ZOrderIndex="2">
      <NestedPanes Count="0" />
    </DockWindow>
    <DockWindow ID="2" DockState="DockRight" ZOrderIndex="3">
      <NestedPanes Count="0" />
    </DockWindow>
    <DockWindow ID="3" DockState="DockTop" ZOrderIndex="4">
      <NestedPanes Count="0" />
    </DockWindow>
    <DockWindow ID="4" DockState="DockBottom" ZOrderIndex="0">
      <NestedPanes Count="2">
        <Pane ID="0" RefID="0" PrevPane="-1" Alignment="Right" Proportion="0.5" />
        <Pane ID="1" RefID="1" PrevPane="0" Alignment="Right" Proportion="0.215625" />
      </NestedPanes>
    </DockWindow>
  </DockWindows>
  <FloatWindows Count="0" />
</DockPanel>

在我的代码中我有三个获取ContentFromPersistString,保存和加载配置文件的DockPanel方法。

private readonly DeserializeDockContent _deserializeDockContent; 

private IDockContent GetContentFromPersistString(string persistString)
        {
            MainLog("GetContentFromPersistString " + persistString);
            if (persistString == typeof(FrmLogging).ToString())
            {
                logToolStripMenuItem.Checked = true;
                _frmLogging.Dock = DockStyle.Fill;
                return _frmLogging;
            }
            else if (persistString == typeof(FrmTimers).ToString())
            {
                timersToolStripMenuItem.Checked = true;
                _frmTimers.Dock = DockStyle.Fill;
                return _frmTimers;
            }
            else if (persistString == typeof(FrmImageAssessmentControl).ToString())
            {
                imageAssessmentToolStripMenuItem.Checked = true;
                _frmIac.Dock = DockStyle.Fill;
                return _frmIac;
            }
            else if (persistString == typeof(FrmRestrictedBrowser).ToString())
            {
                restrictedBrowserToolStripMenuItem.Checked = true;
                _frmRb.Dock = DockStyle.Fill;
                return _frmRb;
            }
            else if (persistString == typeof(FrmGroupCandidates).ToString())
            {
                groupCandidatesToolStripMenuItem.Checked = true;
                _frmGc.Dock = DockStyle.Fill;
                return _frmGc;
            }
            else
            {
                MainLog("Received Window PersistString: " + persistString);
                return null;
            }
        }

        private void LoadDockingWindowsConfiguration()
        {
            MainLog("LoadDockingWindowsConfiguration()");
            // ReSharper disable once AssignNullToNotNullAttribute
            string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "DockPanel.config");

            try
            {
                if (File.Exists(configFile))
                    dockPanel1.LoadFromXml(configFile, _deserializeDockContent);
            }
            catch (Exception ex)
            {
                MainLog("Error: LoadDockingWindowsConfiguration " + ex.Message);
            }

        }

        private void SaveDockingWindowConfiguration()
        {
            MainLog("SaveDockingWindowConfiguration()");
            // ReSharper disable once AssignNullToNotNullAttribute
            string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "DockPanel.config");
            if (_saveLayout)
                dockPanel1.SaveAsXml(configFile);
            else if (File.Exists(configFile))
                File.Delete(configFile);
        }
在MainForm初始化程序中

我有这个:

 _deserializeDockContent = GetContentFromPersistString;  

我们在Form Load事件中加载Docking配置,如下所示:

 LoadDockingWindowsConfiguration();  

这是一个真正令人讨厌的事情,任何将DockContent放置在正确位置的帮助都会受到赞赏。

1 个答案:

答案 0 :(得分:0)

按设计结束,

https://github.com/dockpanelsuite/dockpanelsuite/issues/338

建议DPS用户自行处理异常。