internal void Remove() { if (Parent is SplitContainer parent) { parent.Children.Remove(this); if (parent.Children.Count == 1 && parent.Parent is SplitContainer splitContainerParent) { FrameworkElement child = parent.Children[0]; int parentIndex = splitContainerParent.Children.IndexOf(parent); Size workingSize = SplitContainer.GetWorkingSize(parent); parent.Children.Remove(child); splitContainerParent.Children.RemoveAt(parentIndex); splitContainerParent.Children.Insert(parentIndex, child); SplitContainer.SetWorkingSize(child, workingSize); return; } // Remove the entire split container if there are no more children inside if (parent.Children.Count == 0) { parent.Remove(); } } if (Parent != null) { throw new InvalidOperationException(); } }
private void OnDragCompleted(DragCompletedEventArgs e) { if (resizeData != null) { if (!e.Canceled) { Size beforeElementSize = SplitContainer.GetWorkingSize(BeforeElement); Size afterElementSize = SplitContainer.GetWorkingSize(AfterElement); double totalElementSize = beforeElementSize.Height + afterElementSize.Height; double originalElementsTotalSize = this.resizeData.BeforeElementSize + resizeData.AfterElementSize; if (Orientation == Orientation.Horizontal) { double delta = resizeData.PreviewAdorner.OffsetY / originalElementsTotalSize * totalElementSize; SplitContainer.SetWorkingSize(BeforeElement, new Size(beforeElementSize.Width, beforeElementSize.Height + delta)); SplitContainer.SetWorkingSize(AfterElement, new Size(afterElementSize.Width, afterElementSize.Height - delta)); } else { double delta = this.resizeData.PreviewAdorner.OffsetX / originalElementsTotalSize * totalElementSize; SplitContainer.SetWorkingSize(BeforeElement, new Size(beforeElementSize.Width + delta, beforeElementSize.Height)); SplitContainer.SetWorkingSize(AfterElement, new Size(afterElementSize.Width - delta, afterElementSize.Height)); } } if (VisualTreeHelper.GetParent(resizeData.PreviewAdorner) is AdornerLayer adornerLayer) { adornerLayer.Remove(resizeData.PreviewAdorner); } resizeData = null; } }