public void InsertToRightOf(DockableCollection visual, DockableCollection reference) { LayoutContext visualContext = GetLayoutContext(visual); LayoutContext referenceContext = GetLayoutContext(reference); referenceContext.InsertToRightOf(visualContext); AdjustPostHorizontalInsertion(visualContext, referenceContext); }
internal void InsertByLocation(DockableCollection visual, Rect bounds, System.Windows.Controls.Dock defaultPosition) { using (new Activity(this)) { LayoutContext layoutContext = GetLayoutContext(visual); LayoutContext reference = (LayoutContexts[0] == layoutContext ? LayoutContexts[1] : LayoutContexts[0]); // If the dock resized (smaller) and the bounds are outside the dock, position the visual at the right or bottom edge if (bounds.Left >= ActualWidth) { layoutContext.InsertRight(reference); } else if (bounds.Top >= ActualHeight) { layoutContext.InsertBottom(reference); } else { // Find the visual where the new visual's midpoint was double centerX = (bounds.Left + bounds.Right) / 2; double centerY = (bounds.Top + bounds.Bottom) / 2; LayoutContext midpointReference = FindMidPoint(centerX, centerY); if (midpointReference == null) { // The midpoint is outside the dock InsertByDockPosition(layoutContext, defaultPosition); } else { // Position the visual relative to this reference double referenceX = (midpointReference.Left.Value + midpointReference.Right.Value) / 2; double referenceY = (midpointReference.Top.Value + midpointReference.Bottom.Value) / 2; if (Math.Abs(centerX - referenceX) < MinimumChildSize.Width / 2) { if (centerY < referenceY) { midpointReference.InsertAbove(layoutContext); } else { midpointReference.InsertBelow(layoutContext); } } else if (Math.Abs(centerY - referenceY) < MinimumChildSize.Height / 2) { if (centerX < referenceX) { midpointReference.InsertToLeftOf(layoutContext); } else { midpointReference.InsertToRightOf(layoutContext); } } else { midpointReference.InsertBelow(layoutContext); } } } } }