protected override void OnClosed(EventArgs e) { ReleaseMouseCapture(); DockContainer.Focus(); var dc = DraggedItem as DockControl; var dp = DraggedItem as DockPane; // Tidy up tab buttons if (dc?.TabButton is TabButton tb) { tb.Visibility = Visibility.Visible; } if (m_ghost_button.TabStrip != null) { m_ghost_button.TabStrip.Buttons.Remove(m_ghost_button); } // Commit the move on successful close if (DialogResult == true) { // Preserve the active content var active = DockContainer.ActiveContent; // No address means float in a new floating window if (DropAddress.Length == 0) { // Float the dragged content if (dc != null) { dc.IsFloating = true; } // Or, float the dragged dock pane if (dp != null) { dc = dp.VisibleContent; dp.IsFloating = true; } // Set the location of the floating window to the last position of the ghost if (dc?.TreeHost is FloatingWindow fw) { fw.Left = Ghost.Left; fw.Top = Ghost.Top; } } // Otherwise dock the dragged item at the dock address else if (TreeHost != null) { // Ensure a pane exists at the drop address var target = TreeHost.Root.DockPane(DropAddress); var index = DropIndex ?? target.TabStrip.Buttons.Count; var content = dc != null ? new[] { dc } : dp != null?dp.AllContent.ToArray() : throw new Exception(); // Dock the dragged item(s) foreach (var c in content) { // If we're dropping the item within the same pane, the index needs to be // adjusted if the original index is less than the new index. if (c.DockPane == target && c.TabButton != null && c.DockPane.TabStrip.Buttons.IndexOf(c.TabButton) < index) { --index; } // Even if 'dc.DockPane == target' remove and re-add 'c' because we might be // changing the order c.DockPane = null; target.AllContent.Insert(index++, c); } } // Restore the active content DockContainer.ActiveContent = active; Debug.Assert(DockContainer.ValidateTree()); } Ghost = null !; IndCrossLg = null !; IndCrossSm = null !; IndLeft = null !; IndTop = null !; IndRight = null !; IndBottom = null !; base.OnClosed(e); }