Exemplo n.º 1
0
        private Size ArrangeInternal(Size finalSize, bool finalizeArrangement)
        {
#if POSITIONDUMP
            Debug.Print("ArrangeInternal.finalSize = " + finalSize.ToString());
#endif
            if (LayoutContexts.Count > 0)
            {
                foreach (var child in LayoutContexts)
                {
                    if (LayoutContexts.Count > 1 &&
                        child.Edges[System.Windows.Controls.Dock.Bottom].PhysicalNeighbors.FirstOrDefault() == null &&
                        child.Edges[System.Windows.Controls.Dock.Left].PhysicalNeighbors.FirstOrDefault() == null &&
                        child.Edges[System.Windows.Controls.Dock.Right].PhysicalNeighbors.FirstOrDefault() == null &&
                        child.Edges[System.Windows.Controls.Dock.Top].PhysicalNeighbors.FirstOrDefault() == null)
                    {
                        //  The element hasn't been inserted into the peer graph yet.  Do so.

                        InsertByDockPosition(child, System.Windows.Controls.Dock.Bottom);
                    }

                    child.PreArrange();
                }

retry:

                ArrangeByConvolutedLogic(finalSize);

#if DEBUG
                try
                {
                    foreach (var layoutContext in LayoutContexts)
                    {
                        //  layoutContext.Validate(finalSize);
                    }
                }
                catch (InvalidOperationException)
                {
                    Debugger.Break();
                    foreach (LayoutContext layoutContext in LayoutContexts)
                    {
                        layoutContext.Restore();
                    }
                    goto retry;
                }
#endif
                //  If this is an actual Arrange pass, finalize the arrangement

                if (finalizeArrangement)
                {
                    foreach (var layoutContext in LayoutContexts)
                    {
                        layoutContext.Size.PostArrange();

                        //  Finish laying out the DockableCollection

                        layoutContext.DockableCollection.Arrange(layoutContext.DockableCollection.IsCollapsed ? new Rect() : layoutContext.Bounds);
                        if (layoutContext.DockableCollection.State == DockableCollection.States.Loaded)
                        {
                            layoutContext.DockableCollection.State = DockableCollection.States.Pinned;
                        }
                    }

                    Arranged?.Invoke();
                }

#if POSITIONDUMP
                Dump();
                DumpEdges();
#endif

                //  Return the bounding rectangle for all the children

                return(BoundingSize(LayoutContexts));
            }
            else
            {
                return(finalSize);
            }
        }