This is a migrated thread and some comments may be shown as answers.

restore controlls into docking manager

1 Answer 63 Views
Dock
This is a migrated thread and some comments may be shown as answers.
Wolfgang
Top achievements
Rank 1
Wolfgang asked on 17 Oct 2007, 10:20 AM
hi,

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

}

}

}

}



1 Answer, 1 is accepted

Sort by
0
Julian Benkov
Telerik team
answered on 17 Oct 2007, 01:44 PM
Hi almir kazazic,

Currently, the implementation of the DockingManager only supports docking layout serialization. You must write your business logic for content serialization of IDockable windows like your current implementation.

A good starting point for this is:

http://www.telerik.com/support/kb/article/b454K-mcd-b454T-ckg-b454c-ckg.aspx

Thank you for your time. Please contact us again, if you have additional questions.

Kind regards,
Julian Benkov
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Dock
Asked by
Wolfgang
Top achievements
Rank 1
Answers by
Julian Benkov
Telerik team
Share this question
or