Search code examples
c#xmldockpanel-suite

Loading a WeifenLuo DockPanel Suite layout from XML


I am currently working on a project where I have implemented the DockPanel suite and I am now trying to load the user's layout back from an XML file. The DockPanel object has methods LoadFromXml and SaveToXml. Saving to an XML is relatively simple.

I am unsure how to get the layout loaded back in, whether I need to initialise all of the components again and whether they need to be added back to the form. Any help would be appreciated as there is very little help with this online. I couldn't really work out much from the sample either.

Thank you


Solution

  • Yes, you must provide the components.

    LoadFromXml will restore the dockpanel state (like location, size, etc) of each content, but you are required to actually provide the instances of these DockContent derived items as they are loaded. This is done by providing a handler delegate of type DeserializeDockContent to the LoadFromXml call, which tells you the type it is looking for (by default), and you provide an instance of the appropriate DockContent. An example of this is in MainForm.GetContentFromPersistString() in the DockSample.