0

I inherited a WinForms application where we are using Dock management with WeifenLuo. I'm trying to use the SaveAsXml and LoadFromXml.

Which works fine if I am ok with a new form every time - a particular form needs to stay available right now and I was hoping to be able to just use the code to hide it on close.

The sample app just recreates the controls every time so I'm at a loss.

If I recreate the control it shows fine. However, trying to make it use the already created control never works.

Load XML - attempt doesn't work:

m_deserializeDockContent = new DeserializeDockContent(GetContentFromPersistString);
_dockPanel = null;

InitDockPanel(); //Initialize DockPanel to full screen
_dockPanel.LoadFromXml(filepath, m_deserializeDockContent);
private IDockContent GetContentFromPersistString(string persistString)
{
    if (persistString == typeof(ExistingForm).ToString())
        return existingForm;

    throw new NotImplementedException();
}

At this point I tried the dispose around _dockPanel and handling the dockPanel of the ExistingForm, but nothing seems to change the outcome. Reading online I discovered maybe blocking the close may help, but still doesn't work.

Example of handling the Form close event:

public ExistingForm()
{
    InitializeComponent();
    HideOnClose = true;
    this.FormClosing += ExistingForm_FormClosing;
}

private void ExistingForm_FormClosing(object sender, FormClosingEventArgs e)
{
    e.Cancel = true;
    this.Hide();
}

Updating LoadXml code to include existingForm.DockHandler.Close();, existingForm.DockHandler.Dispose();, or _dockPanel.Dispose();

Which doesn't work at all and I get an error because the form is disposed of.

The only thing that seems to work is recreating the form

if (persistString == typeof(ExistingForm).ToString())
   return new ExistingForm();

Just wondering if I'm missing some handling of the DockHandler (no pun intended).

JGood
  • 522
  • 6
  • 23
  • I was disappointed this was in XML and couldn't quite figure out why these were not loading in properly. For others the answer may be to look at the entire open source library on github and figure it out from there - I went another direction and ended up creating my own LoadFromJSON. I ended up extending DockContent class w/ an enum property type which each extended form now has their own such as Window1 has ContentType = ContentTypeEnum.Window1. Some people may need more, but it's all working now. It's tailored to my needs today so I'd have to generalize to share. – JGood Nov 06 '20 at 18:53
  • https://github.com/dockpanelsuite/dockpanelsuite – JGood Nov 06 '20 at 18:53

0 Answers0