How can I use pre-existing form LoadFromXml in WeifenLuo?

315 Views Asked by At

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).

0

There are 0 best solutions below