1

在此处输入图像描述有时,当我的程序启动时,它无法将 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>

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

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 Event 中加载 Docking 配置,如下所示:

 LoadDockingWindowsConfiguration();  

这是一个真正的麻烦,任何帮助将 DockContent 放置在正确的位置将不胜感激。

4

1 回答 1

0

根据设计得出结论,

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

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

于 2016-09-04T04:44:36.173 回答