コード例 #1
0
         /// <summary>
         /// Handles the NotifyCollectionChangedEventArgs event.
         /// </summary>
         /// <param name="sender">The sender.</param>
         /// <param name="e">The event.</param>
         /// <param name="region">The region.</param>
         /// <param name="regionTarget">The region target.</param>
         void OnViewsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e, IRegion region, DockingManager regionTarget)
         {
             if (e.Action == NotifyCollectionChangedAction.Add)
             {
                 foreach (FrameworkElement item in e.NewItems)
                 {
                     UIElement view = item as UIElement;
                     
                     if (view != null)
                     {
                         //Create a new layout document to be included in the LayoutDocuemntPane (defined in xaml)
                         LayoutDocument newLayoutDocument = new LayoutDocument();
                         //Set the content of the LayoutDocument
                         newLayoutDocument.Content = item;
 
                         ViewModelBase_2 viewModel = (ViewModelBase_2)item.DataContext;
 
                         if (viewModel != null)
                         {
                             //All my viewmodels have a property DisplayName
                             newLayoutDocument.Title = viewModel.DisplayName;
                         }
 
                         //Store all LayoutDocuments alraedy pertaining to the LayoutDocumentPane (defined in xaml)
                         List<LayoutDocument> oldLayoutDocuments = new List<LayoutDocument>();
                         foreach (LayoutDocumentPane oldLayoutDocumentPane in regionTarget.Layout.RootPanel.Children)
                         {
                             foreach (LayoutDocument child in oldLayoutDocumentPane.Children)
                             {
                                 oldLayoutDocuments.Insert(0, child);
                             }
                         }
 
                         //Create a new LayoutDocumentPane and inserts your new LayoutDocument
                         LayoutDocumentPane newLayoutDocumentPane = new LayoutDocumentPane();
                         newLayoutDocumentPane.InsertChildAt(0, newLayoutDocument);
                         
                         //Append to the new LayoutDocumentPane the old LayoutDocuments
                         foreach (LayoutDocument doc in oldLayoutDocuments)
                         {
                             newLayoutDocumentPane.InsertChildAt(0, doc);
                         }
 
                         //Register the new LayoutDocumentPane with the ChildrenCollectionChanged event to manage
                         //LayoutDocuments closure
                         newLayoutDocumentPane.ChildrenCollectionChanged += delegate(
                             Object documentPaneSender, EventArgs args)
                             {
                                 this.OnChildrenCollectionChanged(documentPaneSender, args, region);
                             };
 
                         //Traverse the visual tree of the xaml and replace the LayoutDocumentPane in xaml
                         //with your new LayoutDocumentPane
                         regionTarget.Layout.RootPanel.ReplaceChildAt(0, newLayoutDocumentPane);
                         
                         newLayoutDocument.IsActive = true;
                     }
                 }
             }
         }
コード例 #2
0
        /// <summary>
        /// Handles the NotifyCollectionChangedEventArgs event.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The event.</param>
        /// <param name="region">The region.</param>
        /// <param name="regionTarget">The region target.</param>
        void OnViewsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e, IRegion region, DockingManager regionTarget)
        {
            if (e.Action == NotifyCollectionChangedAction.Add)
            {
                foreach (FrameworkElement item in e.NewItems)
                {
                    UIElement view = item as UIElement;

                    if (view != null)
                    {
                        //Create a new layout document to be included in the LayoutDocuemntPane (defined in xaml)
                        LayoutDocument newLayoutDocument = new LayoutDocument();
                        //Set the content of the LayoutDocument
                        newLayoutDocument.Content = item;

                        //Allows us to add an title and Icon to the Document

                        /*ViewModelBase viewModel = (ViewModelBase)item.DataContext;
                         *
                         * if (viewModel != null)
                         * {*/
                        //All my viewmodels have properties DisplayName and IconKey
                        newLayoutDocument.Title = "test";

                        /*
                         *  //GetImageUri is custom made method which gets the icon for the LayoutDocument
                         *  newLayoutDocument.IconSource = this.GetImageUri(viewModel.IconKey);
                         * }*/

                        //Store all LayoutDocuments already pertaining to the LayoutDocumentPane (defined in xaml)
                        List <LayoutDocument> oldLayoutDocuments = new List <LayoutDocument>();

                        //Get the current ILayoutDocumentPane ... Depending on the arrangement of the views this can be either
                        //a simple LayoutDocumentPane or a LayoutDocumentPaneGroup
                        ILayoutDocumentPane currentILayoutDocumentPane = (ILayoutDocumentPane)regionTarget.Layout.RootPanel.Children[0];

                        if (currentILayoutDocumentPane.GetType() == typeof(LayoutDocumentPaneGroup))
                        {
                            //If the current ILayoutDocumentPane turns out to be a group
                            //Get the children (LayoutDocuments) of the first pane
                            LayoutDocumentPane oldLayoutDocumentPane = (LayoutDocumentPane)currentILayoutDocumentPane.Children.ToList()[0];
                            foreach (LayoutDocument child in oldLayoutDocumentPane.Children)
                            {
                                oldLayoutDocuments.Insert(0, child);
                            }
                        }
                        else if (currentILayoutDocumentPane.GetType() == typeof(LayoutDocumentPane))
                        {
                            //If the current ILayoutDocumentPane turns out to be a simple pane
                            //Get the children (LayoutDocuments) of the single existing pane.
                            foreach (LayoutDocument child in currentILayoutDocumentPane.Children)
                            {
                                oldLayoutDocuments.Insert(0, child);
                            }
                        }

                        //Create a new LayoutDocumentPane and inserts your new LayoutDocument
                        LayoutDocumentPane newLayoutDocumentPane = new LayoutDocumentPane();
                        newLayoutDocumentPane.InsertChildAt(0, newLayoutDocument);

                        //Append to the new LayoutDocumentPane the old LayoutDocuments
                        foreach (LayoutDocument doc in oldLayoutDocuments)
                        {
                            newLayoutDocumentPane.InsertChildAt(0, doc);
                        }

                        //Traverse the visual tree of the xaml and replace the LayoutDocumentPane (or LayoutDocumentPaneGroup) in xaml
                        //with your new LayoutDocumentPane (or LayoutDocumentPaneGroup)
                        if (currentILayoutDocumentPane.GetType() == typeof(LayoutDocumentPane))
                        {
                            regionTarget.Layout.RootPanel.ReplaceChildAt(0, newLayoutDocumentPane);
                        }
                        else if (currentILayoutDocumentPane.GetType() == typeof(LayoutDocumentPaneGroup))
                        {
                            currentILayoutDocumentPane.ReplaceChild(currentILayoutDocumentPane.Children.ToList()[0], newLayoutDocumentPane);
                            regionTarget.Layout.RootPanel.ReplaceChildAt(0, currentILayoutDocumentPane);
                        }
                        newLayoutDocument.IsActive = true;
                    }
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Handles the NotifyCollectionChangedEventArgs event.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The event.</param>
        /// <param name="region">The region.</param>
        /// <param name="regionTarget">The region target.</param>
        void OnViewsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e, IRegion region, DockingManager regionTarget)
        {
            if (e.Action == NotifyCollectionChangedAction.Remove)
            {
                foreach (var eOldItem in e.OldItems)
                {
                    var disposables = new[]
                    {
                        eOldItem as IDisposable,
                        (eOldItem as FrameworkElement)?.DataContext as IDisposable,
                        (eOldItem as ContentControl)?.Content as IDisposable,
                        ((eOldItem as ContentControl)?.Content as FrameworkElement)?.DataContext as IDisposable
                    };

                    foreach (var disposable in disposables)
                    {
                        disposable?.Dispose();
                    }
                }
            }

            if (e.Action == NotifyCollectionChangedAction.Add)
            {
                foreach (FrameworkElement item in e.NewItems)
                {
                    UIElement view = item;

                    if (view != null)
                    {
                        //Create a new layout document to be included in the LayoutDocuemntPane (defined in xaml)
                        LayoutDocument newLayoutDocument = new LayoutDocument();
                        //Set the content of the LayoutDocument
                        newLayoutDocument.Content = item;
                        newLayoutDocument.Title   = (item.DataContext as ITitledItem)?.Title;

                        ServerMonitorModel viewModel = item.DataContext as ServerMonitorModel;
                        if (viewModel != null)
                        {
                            //All my viewmodels have properties DisplayName and IconKey
                            newLayoutDocument.Title = viewModel.CurrentServer.Name;
                            viewModel.OpenServer();
                            newLayoutDocument.Closed += (s, a) =>
                            {
                                Task.Factory.StartNew(() =>
                                {
                                    viewModel.CloseServer();
                                    viewModel.Cleanup();
                                });
                            };
                        }

                        //Store all LayoutDocuments already pertaining to the LayoutDocumentPane (defined in xaml)
                        List <LayoutDocument> oldLayoutDocuments = new List <LayoutDocument>();
                        //Get the current ILayoutDocumentPane ... Depending on the arrangement of the views this can be either
                        //a simple LayoutDocumentPane or a LayoutDocumentPaneGroup
                        ILayoutDocumentPane currentILayoutDocumentPane = (ILayoutDocumentPane)regionTarget.Layout.RootPanel.Children[0];

                        if (currentILayoutDocumentPane.GetType() == typeof(LayoutDocumentPaneGroup))
                        {
                            //If the current ILayoutDocumentPane turns out to be a group
                            //Get the children (LayoutDocuments) of the first pane
                            LayoutDocumentPane oldLayoutDocumentPane = (LayoutDocumentPane)currentILayoutDocumentPane.Children.ToList()[0];
                            foreach (LayoutDocument child in oldLayoutDocumentPane.Children)
                            {
                                oldLayoutDocuments.Insert(0, child);
                            }
                        }
                        else if (currentILayoutDocumentPane.GetType() == typeof(LayoutDocumentPane))
                        {
                            //If the current ILayoutDocumentPane turns out to be a simple pane
                            //Get the children (LayoutDocuments) of the single existing pane.
                            foreach (LayoutDocument child in currentILayoutDocumentPane.Children)
                            {
                                oldLayoutDocuments.Insert(0, child);
                            }
                        }

                        //Create a new LayoutDocumentPane and inserts your new LayoutDocument
                        LayoutDocumentPane newLayoutDocumentPane = new LayoutDocumentPane();
                        newLayoutDocumentPane.InsertChildAt(0, newLayoutDocument);

                        //Append to the new LayoutDocumentPane the old LayoutDocuments
                        foreach (LayoutDocument doc in oldLayoutDocuments)
                        {
                            newLayoutDocumentPane.InsertChildAt(0, doc);
                        }

                        //Traverse the visual tree of the xaml and replace the LayoutDocumentPane (or LayoutDocumentPaneGroup) in xaml
                        //with your new LayoutDocumentPane (or LayoutDocumentPaneGroup)
                        if (currentILayoutDocumentPane.GetType() == typeof(LayoutDocumentPane))
                        {
                            regionTarget.Layout.RootPanel.ReplaceChildAt(0, newLayoutDocumentPane);
                        }
                        else if (currentILayoutDocumentPane.GetType() == typeof(LayoutDocumentPaneGroup))
                        {
                            currentILayoutDocumentPane.ReplaceChild(currentILayoutDocumentPane.Children.ToList()[0], newLayoutDocumentPane);
                            regionTarget.Layout.RootPanel.ReplaceChildAt(0, currentILayoutDocumentPane);
                        }

                        newLayoutDocument.IsActive = true;
                    }
                }
            }
        }
コード例 #4
0
        public void UpdateDocMinWidthHeightTest()
        {
            double             documentPaneDockMinHeight = 100;
            double             documentPaneDockMinWidth  = 101;
            LayoutDocumentPane layoutDocumentPane        = new LayoutDocumentPane {
                DockMinHeight = documentPaneDockMinHeight, DockMinWidth = documentPaneDockMinWidth
            };

            layoutDocumentPane.InsertChildAt(0, new LayoutDocument {
                ContentId = "Document"
            });

            LayoutDocumentPaneGroup layoutDocumentPaneGroup = new LayoutDocumentPaneGroup();

            layoutDocumentPaneGroup.InsertChildAt(0, layoutDocumentPane);

            double anchorablePane1DockMinHeight        = 150;
            double anchorablePane1DockMinWidth         = 151;
            LayoutAnchorablePane layoutAnchorablePane1 = new LayoutAnchorablePane {
                DockMinHeight = anchorablePane1DockMinHeight, DockMinWidth = anchorablePane1DockMinWidth
            };

            layoutAnchorablePane1.InsertChildAt(0, new LayoutAnchorable {
                ContentId = "Anchorable1"
            });

            double anchorablePane2DockMinHeight        = 200;
            double anchorablePane2DockMinWidth         = 201;
            LayoutAnchorablePane layoutAnchorablePane2 = new LayoutAnchorablePane {
                DockMinHeight = anchorablePane2DockMinHeight, DockMinWidth = anchorablePane2DockMinWidth
            };

            layoutAnchorablePane2.InsertChildAt(0, new LayoutAnchorable {
                ContentId = "Anchorable2"
            });

            LayoutAnchorablePaneGroup layoutAnchorablePaneGroup = new LayoutAnchorablePaneGroup {
                Orientation = Orientation.Horizontal
            };

            layoutAnchorablePaneGroup.InsertChildAt(0, layoutAnchorablePane1);
            layoutAnchorablePaneGroup.InsertChildAt(0, layoutAnchorablePane2);

            LayoutPanel layoutPanel = new LayoutPanel {
                Orientation = Orientation.Vertical
            };

            layoutPanel.InsertChildAt(0, layoutDocumentPaneGroup);
            layoutPanel.InsertChildAt(1, layoutAnchorablePaneGroup);

            Assert.AreEqual(anchorablePane2DockMinWidth + anchorablePane1DockMinWidth, layoutAnchorablePaneGroup.CalculatedDockMinWidth());
            Assert.AreEqual(Math.Max(anchorablePane2DockMinHeight, anchorablePane1DockMinHeight), layoutAnchorablePaneGroup.CalculatedDockMinHeight());

            Assert.AreEqual(documentPaneDockMinWidth, layoutDocumentPaneGroup.CalculatedDockMinWidth());
            Assert.AreEqual(documentPaneDockMinHeight, layoutDocumentPaneGroup.CalculatedDockMinHeight());

            Assert.AreEqual(
                Math.Max(anchorablePane1DockMinWidth + anchorablePane2DockMinWidth, documentPaneDockMinWidth),
                layoutPanel.CalculatedDockMinWidth());

            Assert.AreEqual(documentPaneDockMinHeight + anchorablePane2DockMinHeight, layoutPanel.CalculatedDockMinHeight());
        }
コード例 #5
0
        public void CalculatedDockMinWidthHeightTest()
        {
            double defaultDockMinHeight = 25;
            double defaultDockMinWidth  = 25;

            const double       documentPaneDockMinHeight = 200;
            const double       documentPaneDockMinWidth  = 400;
            LayoutDocumentPane layoutDocumentPane        = new LayoutDocumentPane {
                DockMinHeight = documentPaneDockMinHeight, DockMinWidth = documentPaneDockMinWidth
            };

            layoutDocumentPane.InsertChildAt(0, new LayoutDocument {
                ContentId = "Document"
            });

            LayoutDocumentPaneGroup layoutDocumentPaneGroup = new LayoutDocumentPaneGroup();

            layoutDocumentPaneGroup.InsertChildAt(0, layoutDocumentPane);

            const double         anchorablePaneDockMinHeight = 80;
            const double         anchorablePaneDockMinWidth  = 160;
            LayoutAnchorablePane layoutAnchorablePane        = new LayoutAnchorablePane {
                DockMinHeight = anchorablePaneDockMinHeight, DockMinWidth = anchorablePaneDockMinWidth
            };

            layoutAnchorablePane.InsertChildAt(0, new LayoutAnchorable {
                ContentId = "Anchorable"
            });

            LayoutAnchorablePaneGroup layoutAnchorablePaneGroup = new LayoutAnchorablePaneGroup();

            layoutAnchorablePaneGroup.InsertChildAt(0, layoutAnchorablePane);

            LayoutPanel layoutPanel = new LayoutPanel();

            layoutPanel.InsertChildAt(0, layoutDocumentPaneGroup);
            layoutPanel.InsertChildAt(1, layoutAnchorablePaneGroup);

            Assert.AreEqual(defaultDockMinWidth, layoutPanel.DockMinWidth);
            Assert.AreEqual(defaultDockMinHeight, layoutPanel.DockMinHeight);
            Assert.AreEqual(documentPaneDockMinWidth + anchorablePaneDockMinWidth, layoutPanel.CalculatedDockMinWidth());
            Assert.AreEqual(Math.Max(documentPaneDockMinHeight, anchorablePaneDockMinHeight), layoutPanel.CalculatedDockMinHeight());

            Assert.AreEqual(documentPaneDockMinWidth, layoutDocumentPane.DockMinWidth);
            Assert.AreEqual(documentPaneDockMinHeight, layoutDocumentPane.DockMinHeight);
            Assert.AreEqual(layoutDocumentPane.DockMinWidth, layoutDocumentPane.CalculatedDockMinWidth());
            Assert.AreEqual(layoutDocumentPane.DockMinHeight, layoutDocumentPane.CalculatedDockMinHeight());

            Assert.AreEqual(defaultDockMinWidth, layoutDocumentPaneGroup.DockMinWidth);
            Assert.AreEqual(defaultDockMinWidth, layoutDocumentPaneGroup.DockMinHeight);
            Assert.AreEqual(documentPaneDockMinWidth, layoutDocumentPaneGroup.CalculatedDockMinWidth());
            Assert.AreEqual(documentPaneDockMinHeight, layoutDocumentPaneGroup.CalculatedDockMinHeight());

            Assert.AreEqual(anchorablePaneDockMinWidth, layoutAnchorablePane.DockMinWidth);
            Assert.AreEqual(anchorablePaneDockMinHeight, layoutAnchorablePane.DockMinHeight);
            Assert.AreEqual(layoutAnchorablePane.DockMinWidth, layoutAnchorablePane.CalculatedDockMinWidth());
            Assert.AreEqual(layoutAnchorablePane.DockMinHeight, layoutAnchorablePane.CalculatedDockMinHeight());

            Assert.AreEqual(defaultDockMinWidth, layoutAnchorablePaneGroup.DockMinWidth);
            Assert.AreEqual(defaultDockMinWidth, layoutAnchorablePaneGroup.DockMinHeight);
            Assert.AreEqual(anchorablePaneDockMinWidth, layoutAnchorablePaneGroup.CalculatedDockMinWidth());
            Assert.AreEqual(anchorablePaneDockMinHeight, layoutAnchorablePaneGroup.CalculatedDockMinHeight());

            layoutPanel.RemoveChild(layoutDocumentPaneGroup);
            Assert.AreEqual(anchorablePaneDockMinWidth, layoutPanel.CalculatedDockMinWidth());
            Assert.AreEqual(anchorablePaneDockMinHeight, layoutPanel.CalculatedDockMinHeight());
        }
コード例 #6
0
        /// <summary>
        /// Handles the NotifyCollectionChangedEventArgs event.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The event.</param>
        /// <param name="region">The region.</param>
        /// <param name="regionTarget">The region target.</param>
        void OnViewsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e, IRegion region, DockingManager regionTarget)
        {
            if (e.Action == NotifyCollectionChangedAction.Add)
            {
                foreach (FrameworkElement item in e.NewItems)
                {
                    UIElement view = item as UIElement;

                    if (view != null)
                    {
                        //Create a new layout document to be included in the LayoutDocuemntPane (defined in xaml)
                        LayoutDocument newLayoutDocument = new LayoutDocument();
                        //Set the content of the LayoutDocument
                        newLayoutDocument.Content = item;

                        /*IDecompileViewModel viewModel = item.DataContext as IDecompileViewModel;
                         *
                         * if (viewModel != null)
                         * {
                         *  Binding binding = new Binding("Title") { Source = viewModel,Mode=BindingMode.OneWay };
                         *  BindingOperations.SetBinding(newLayoutDocument, LayoutDocument.TitleProperty, binding);
                         * }*/

                        //Store all LayoutDocuments already pertaining to the LayoutDocumentPane (defined in xaml)
                        List <LayoutDocument> oldLayoutDocuments = new List <LayoutDocument>();
                        //Get the current ILayoutDocumentPane ... Depending on the arrangement of the views this can be either
                        //a simple LayoutDocumentPane or a LayoutDocumentPaneGroup
                        ILayoutDocumentPane currentILayoutDocumentPane = (ILayoutDocumentPane)regionTarget.Layout.RootPanel.Children[0];

                        if (currentILayoutDocumentPane.GetType() == typeof(LayoutDocumentPaneGroup))
                        {
                            //If the current ILayoutDocumentPane turns out to be a group
                            //Get the children (LayoutDocuments) of the first pane

                            LayoutDocumentPane oldLayoutDocumentPane = (LayoutDocumentPane)currentILayoutDocumentPane.Children.ToList()[0];
                            foreach (LayoutDocument child in oldLayoutDocumentPane.Children)
                            {
                                oldLayoutDocuments.Insert(0, child);
                            }
                        }
                        else if (currentILayoutDocumentPane.GetType() == typeof(LayoutDocumentPane))
                        {
                            //If the current ILayoutDocumentPane turns out to be a simple pane
                            //Get the children (LayoutDocuments) of the single existing pane.
                            foreach (LayoutDocument child in currentILayoutDocumentPane.Children)
                            {
                                oldLayoutDocuments.Insert(0, child);
                            }
                        }

                        //Create a new LayoutDocumentPane and inserts your new LayoutDocument
                        LayoutDocumentPane newLayoutDocumentPane = new LayoutDocumentPane();
                        newLayoutDocumentPane.InsertChildAt(0, newLayoutDocument);

                        //Append to the new LayoutDocumentPane the old LayoutDocuments
                        foreach (LayoutDocument doc in oldLayoutDocuments)
                        {
                            newLayoutDocumentPane.InsertChildAt(0, doc);
                        }

                        //Traverse the visual tree of the xaml and replace the LayoutDocumentPane (or LayoutDocumentPaneGroup) in xaml
                        //with your new LayoutDocumentPane (or LayoutDocumentPaneGroup)
                        if (currentILayoutDocumentPane.GetType() == typeof(LayoutDocumentPane))
                        {
                            regionTarget.Layout.RootPanel.ReplaceChildAt(0, newLayoutDocumentPane);
                        }
                        else if (currentILayoutDocumentPane.GetType() == typeof(LayoutDocumentPaneGroup))
                        {
                            currentILayoutDocumentPane.ReplaceChild(currentILayoutDocumentPane.Children.ToList()[0], newLayoutDocumentPane);
                            regionTarget.Layout.RootPanel.ReplaceChildAt(0, currentILayoutDocumentPane);
                        }
                        newLayoutDocument.IsActive = true;
                    }
                }
            }
        }
コード例 #7
0
        private static void OnViewsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e, IRegion region, DockingManager regionTarget)
        {
            if (e.Action != NotifyCollectionChangedAction.Add)
            {
                return;
            }

            foreach (ActiveView item in e.NewItems)
            {
                var view = item.View;
                if (view == null)
                {
                    continue;
                }

                //Create a new layout document to be included in the LayoutDocuemntPane (defined in xaml)
                var newLayoutDocument = new PresenterLayoutDocument(item);

                //Store all LayoutDocuments already pertaining to the LayoutDocumentPane (defined in xaml)
                var oldLayoutDocuments = new List <LayoutDocument>();
                //Get the current ILayoutDocumentPane ... Depending on the arrangement of the views this can be either
                //a simple LayoutDocumentPane or a LayoutDocumentPaneGroup
                var currentILayoutDocumentPane = (ILayoutDocumentPane)regionTarget.Layout.RootPanel.Children[0];

                if (currentILayoutDocumentPane.GetType() == typeof(LayoutDocumentPaneGroup))
                {
                    //If the current ILayoutDocumentPane turns out to be a group
                    //Get the children (LayoutDocuments) of the first pane
                    var oldLayoutDocumentPane = (LayoutDocumentPane)currentILayoutDocumentPane.Children.ToList()[0];
                    foreach (var child in oldLayoutDocumentPane.Children.Cast <LayoutDocument>())
                    {
                        oldLayoutDocuments.Insert(0, child);
                    }
                }
                else if (currentILayoutDocumentPane.GetType() == typeof(LayoutDocumentPane))
                {
                    //If the current ILayoutDocumentPane turns out to be a simple pane
                    //Get the children (LayoutDocuments) of the single existing pane.
                    foreach (var child in currentILayoutDocumentPane.Children.Cast <LayoutDocument>())
                    {
                        oldLayoutDocuments.Insert(0, child);
                    }
                }

                //Create a new LayoutDocumentPane and inserts your new LayoutDocument
                var newLayoutDocumentPane = new LayoutDocumentPane();
                newLayoutDocumentPane.InsertChildAt(0, newLayoutDocument);

                //Append to the new LayoutDocumentPane the old LayoutDocuments
                foreach (var doc in oldLayoutDocuments)
                {
                    newLayoutDocumentPane.InsertChildAt(0, doc);
                }

                newLayoutDocumentPane.SelectedContentIndex = newLayoutDocumentPane.IndexOf(newLayoutDocument);


                //Traverse the visual tree of the xaml and replace the LayoutDocumentPane (or LayoutDocumentPaneGroup) in xaml
                //with your new LayoutDocumentPane (or LayoutDocumentPaneGroup)
                if (currentILayoutDocumentPane.GetType() == typeof(LayoutDocumentPane))
                {
                    regionTarget.Layout.RootPanel.ReplaceChildAt(0, newLayoutDocumentPane);
                }
                else if (currentILayoutDocumentPane.GetType() == typeof(LayoutDocumentPaneGroup))
                {
                    currentILayoutDocumentPane.ReplaceChild(currentILayoutDocumentPane.Children.ToList()[0], newLayoutDocumentPane);
                    regionTarget.Layout.RootPanel.ReplaceChildAt(0, currentILayoutDocumentPane);
                }
                newLayoutDocument.IsActive = true;
            }
        }