[Version 2.0] Loading Layout doesn't attach new LayoutDoucments

Jan 21, 2015 at 4:04 PM
I have a Docking control that will dynamically insert LayoutDocuments in code during initialization. After inserting the LayoutDocuments, a previously saved XML layout is deserialized into the Docking control. If there is a new LayoutDocuement that wasn't included in the last save, it doesn't display in the docking window.

I'm able to workaround this issue by manually attaching the documents. Is this an outstanding issue with the control? Does the code below make sense, or is there a better method?
        /// <summary>
        /// Fixes the docking layout after loading settings.
        /// </summary>
        /// <param name="dockingManager">The docking manager.</param>
        /// <param name="documentPane">The document pane.</param>
        public static void FixDockingLayout(DockingManager dockingManager, ILayoutDocumentPane documentPane)
        {
            var docmentPaneGroup = dockingManager.Layout.RootPanel.Children[0] as LayoutDocumentPaneGroup;
            if (docmentPaneGroup == null || docmentPaneGroup.Children.Count == 0)
            {
                return;
            }

            // Get all documents attached to the layout
            var attchedDocuments = new List<LayoutContent>();
            var documentPanes = docmentPaneGroup.Children.Cast<LayoutDocumentPane>().ToArray();
            foreach (var pane in documentPanes)
            {
                attchedDocuments.AddRange(pane.ChildrenSorted);
            }

            // Get all documents that are in a floating window
            foreach (var floatingWindow in dockingManager.Layout.FloatingWindows)
            {
                // Remove floating windows that have no children to prevent crash
                if (floatingWindow.ChildrenCount == 0)
                {
                    dockingManager.Layout.RemoveChild(floatingWindow);
                    break;
                }

                attchedDocuments.AddRange(floatingWindow.Children.Cast<LayoutContent>());
            }

            // Attach documents that are not in the layout
            var documentsNotInLayout = documentPane.Children.Cast<LayoutContent>().Except(attchedDocuments, new LayoutComparer()).ToArray();
            foreach (var document in documentsNotInLayout)
            {
                documentPanes[0].InsertChildAt(documentPanes[0].ChildrenSorted.Count(), document);
            }
        }