i wanted to restore all elements into my docking manaer, i could not use this solution as i do not know how many panells i will have and what kind of usercontorlls they will host , i do not want to make if/then for each control deserialization so I wrot this code, which uses aditional xml file to store data about controls stored in panels, and than it uses reflection to reinitilize it
private void SaveLayout()
{
dockingManager1.SaveXML(fileName);
XmlDocument doc = new XmlDocument();
XmlElement root = doc.CreateElement("SerializedControlCollection");
doc.AppendChild(root);
//go through the sites
foreach (IDockingSite site in dockingManager1.DockingSites)
{
//now get panels
foreach (DockPanel pan in site.ManagedDockables)
{
//check if there is anything in panel
if (pan.Controls.Count > 0)
{
//get first child of panel, this one is interesting for me
UserControl userControl = pan.Controls[0] as UserControl;
//check if this is user control
if (userControl != null)
{
XmlElement contElement = doc.CreateElement("Control");
XmlAttribute att = doc.CreateAttribute("DockableGuid");
contElement.Attributes.Append(att);
att.InnerText = pan.ID.ToString();
contElement.InnerText = userControl.GetType().FullName;
root.AppendChild(contElement);
}
}
}
}
doc.Save(controlFile);
}
private void RestoreLayout()
{
if (File.Exists(fileName))
{
dockingManager1.LoadXML(fileName);
}
XmlDataDocument controlInfo = new XmlDataDocument();
controlInfo.Load(controlFile);
//create hashtable to make it easier later
Dictionary<string, string> idToTypeMap=new Dictionary<string, string>();
foreach (XmlElement el in controlInfo.FirstChild.ChildNodes)
{
string guid = el.GetAttribute("DockableGuid");
idToTypeMap[guid] = el.InnerText;
}
//restore contorls inside
foreach (IDockingSite site in dockingManager1.DockingSites)
{
//now get panels
foreach (DockPanel pan in site.ManagedDockables)
{
if(idToTypeMap.ContainsKey(pan.ID.ToString()))
{
string typeName = idToTypeMap[pan.ID.ToString()];
Type t = this.GetType().Assembly.GetType(typeName);
Control con = (Control) Activator.CreateInstance(t);
pan.Controls.Add(con);
}
}
}
}