restore controlls into docking manager

2 posts, 0 answers
  1. Wolfgang
    Wolfgang avatar
    7 posts
    Member since:
    Oct 2007

    Posted 17 Oct 2007 Link to this post

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

    }

    }

    }

    }



  2. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 17 Oct 2007 Link to this post

    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
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top