// takes a LSP content item and splits it into a new LSP, combined with the new window private void SplitCell(WindowBase windowToDrop, EdgeDockingDropZone dropZone) { if (!(dropZone.Data is ControlBase)) return; //orphan the window being dropped windowToDrop.ContainerContext.RemoveChild(windowToDrop); if (windowToDrop is IOrientingControl) { ((IOrientingControl)windowToDrop).Orientation = Orientation == LUCAStackPanelOrientation.Horizontal ? System.Windows.Controls.Orientation.Horizontal : System.Windows.Controls.Orientation.Vertical; } var targetWindow = dropZone.Data as ControlBase; if (Children.Count <= 1) { //flip the orientation Orientation = Orientation == LUCAStackPanelOrientation.Horizontal ? LUCAStackPanelOrientation.Vertical : LUCAStackPanelOrientation.Horizontal; UpdateLastKnownDimensions(this, windowToDrop); switch (dropZone.InsertType) { case InsertType.Left: case InsertType.Top: //the dropped window is first in the new stack InsertChild(0, windowToDrop); break; case InsertType.Right: case InsertType.Bottom: //the target window is first in the new stack AddChild(windowToDrop); break; default: throw new LUCAControlException("Incorrect Insert Type"); } windowToDrop.ContainerContext = this; } else { //capture the position of the target window var index = Children.IndexOf(targetWindow); var newLsp = new LUCAStackPanel { Orientation = Orientation == LUCAStackPanelOrientation.Horizontal ? LUCAStackPanelOrientation.Vertical : LUCAStackPanelOrientation.Horizontal }; UpdateLastKnownDimensions(newLsp, windowToDrop); //insert the new LSP into the parent LSP InsertChild(index, newLsp); //orphan the targetWindow RemoveChild(targetWindow); switch (dropZone.InsertType) { case InsertType.Left: case InsertType.Top: //the dropped window is first in the new stack newLsp.AddChild(windowToDrop); newLsp.AddChild(targetWindow); break; case InsertType.Right: case InsertType.Bottom: //the target window is first in the new stack newLsp.AddChild(targetWindow); newLsp.AddChild(windowToDrop); break; default: throw new LUCAControlException("Incorrect Insert Type"); } //assign parent relationships targetWindow.ContainerContext = newLsp; windowToDrop.ContainerContext = newLsp; } }
// takes the LSP and moves it into a new parent container LSP which is split with the window being dropped private void Split(WindowBase windowToDrop, EdgeDockingDropZone dropZone) { // remove the window from it's current parent container windowToDrop.ContainerContext.RemoveChild(windowToDrop); UpdateLastKnownDimensions(this, windowToDrop); if (windowToDrop is IOrientingControl) { ((IOrientingControl)windowToDrop).Orientation = Orientation == LUCAStackPanelOrientation.Horizontal ? System.Windows.Controls.Orientation.Horizontal : System.Windows.Controls.Orientation.Vertical; } if (Children.Count <= 1) { switch (dropZone.InsertType) { case InsertType.Left: case InsertType.Top: //the dropped window is first in the new stack InsertChild(0, windowToDrop); break; case InsertType.Right: case InsertType.Bottom: //the target window is first in the new stack AddChild(windowToDrop); break; default: throw new LUCAControlException("Incorrect Insert Type"); } windowToDrop.ContainerContext = this; } else { // capture the current index of this LSP var ix = ContainerContext.Children.IndexOf(this); // store the parent container for this LUCAStackPanel var plc = ContainerContext; // remove this LUCAStackPanel from it's parent container so we can remerge it later into a new LUCAStackPanel ContainerContext.RemoveChild(this); // create a new LUCAStackPanel for the window and this LSP. Toggling the orientation from this LSP. var newLsp = new LUCAStackPanel { Orientation = Orientation == LUCAStackPanelOrientation.Horizontal ? LUCAStackPanelOrientation.Vertical : LUCAStackPanelOrientation.Horizontal, }; UpdateLastKnownDimensions(newLsp, windowToDrop); //add the new LSP to the original parent container plc.InsertChild(ix, newLsp); //get the order correct if (dropZone.InsertType == InsertType.Top || dropZone.InsertType == InsertType.Left) { newLsp.AddChild(windowToDrop); newLsp.AddChild(this); } else { newLsp.AddChild(this); newLsp.AddChild(windowToDrop); } //assign parent relationships ContainerContext = newLsp; windowToDrop.ContainerContext = newLsp; //if this LSP has only 1 child, then Rebuild the layout so that it is actually removed and replaced by its' child. if (Children.Count == 1) RebuildGridLayout(); } }