private void DetachHandlers(TearableTabControl ttc) { if (null != ttc) { ttc.ItemsChanged -= TearableTabControl_ItemsChanged; } }
public bool AddControl(DropLocation location, TearableTabControl existingTabControl, TearableTabItem newTabItem, ref Grid droppedItemParent) { TearableTabControl ttcNew = new TearableTabControl(); TearableTabControl newTabItemParent = newTabItem.Parent as TearableTabControl; if (!ttcNew.DropTab(newTabItem)) { } switch (location) { case DropLocation.Left: ttcLeft = ttcNew; ttcRight = existingTabControl; break; case DropLocation.Right: ttcLeft = existingTabControl; ttcRight = ttcNew; break; case DropLocation.Center: case DropLocation.Top: case DropLocation.Bottom: default: throw new NotSupportedException("Only left and right locations are supported in Horizontal"); } // This is where it seems to go wrong as well as in TTSH // Start { droppedItemParent = existingTabControl.Parent as Grid; if (null != droppedItemParent) { droppedItemParent.Children.Remove(existingTabControl); } else { } if (this.IsChildOf(newTabItem)) { } // } end gridContentVertical.Children.Insert(0, ttcLeft); Grid.SetColumn(ttcLeft, 0); gridContentVertical.Children.Insert(0, ttcRight); Grid.SetColumn(ttcRight, 2); AttachHandlers(ttcLeft); AttachHandlers(ttcRight); ttddLeft.AttachDetectorElement(ttcLeft); ttddRight.AttachDetectorElement(ttcRight); AttachHandlers(ttddLeft); AttachHandlers(ttddRight); return(true); }
public void Remove(ref ITabControlContainer itcc, ref TearableTabControl ttc, ref TearableTabDropDetector ttdd, TearableTabControl ttcToBeInserted, int insertIndex) { gridContentVertical.Children.Remove(itcc as UIElement); itcc = null; ttc = ttcToBeInserted; AttachHandlers(ttc); ttdd.Visibility = Visibility.Visible; ttdd.AttachDetectorElement(ttc); gridContentVertical.Children.Insert(0, ttc); Grid.SetColumn(ttc, insertIndex); }
private void TearableTabControl_ItemsChanged(object sender, NotifyCollectionChangedEventArgs e) { TearableTabControl ttc = sender as TearableTabControl; if (null != ttc) { if (0 == ttc.Items.Count) { DetachHandlers(ttcLeft); DetachHandlers(ttcRight); ttddLeft.DetachDetectorElement(); ttddRight.DetachDetectorElement(); DetachHandlers(ttddLeft); DetachHandlers(ttddRight); if (ttc == ttcLeft) { ttcLeft = null; if (null != ttcRight) { gridContentVertical.Children.Remove(ttcRight); TabParent.RemoveControl(this, ttcRight); ttcRight = null; } else if (null != itccRight) { gridContentVertical.Children.Remove(itccRight as UIElement); itccRight.TabParent = this.TabParent; TabParent.RemoveControl(this, itccRight as FrameworkElement); itccRight = null; } else { (this.Parent as Grid).Children.Remove(this); //throw new NullReferenceException("Both ttcRight and itccRight cannot be null"); } } else if (ttc == ttcRight) { if (ttcLeft?.Items.Count == 0) { } ttcRight = null; if (null != ttcLeft) { gridContentVertical.Children.Remove(ttcLeft); TabParent.RemoveControl(this, ttcLeft); ttcLeft = null; } else if (null != itccLeft) { gridContentVertical.Children.Remove(itccLeft as UIElement); itccLeft.TabParent = this.TabParent; TabParent.RemoveControl(this, itccLeft as FrameworkElement); itccLeft = null; } else { throw new NullReferenceException("Both ttcLeft and itccLeft cannot be null"); } } else { throw new NotSupportedException("Child object not supported"); } } } }
public bool AddSplitControl(DropLocation location, DropLocation sourceLoaction, TearableTabItem ttItem) { ITabControlContainer itcc; Grid droppedItemParent = null; switch (location) { case DropLocation.Top: case DropLocation.Bottom: itcc = new TearableTabSplitHorizontal(this); break; case DropLocation.Left: case DropLocation.Right: itcc = new TearableTabSplitVertical(this); break; case DropLocation.Center: default: throw new NotSupportedException("Center not supported"); } switch (sourceLoaction) { case DropLocation.Left: if (ttcLeft.Items.Contains(ttItem) && 1 == ttcLeft.Items.Count) { return(false); } DetachHandlers(ttcLeft); gridContentVertical.Children.Remove(ttcLeft); TearableTabControl ttcLeftTmp = ttcLeft; if (ttcLeft == null) { } if (itcc.AddControl(location, ttcLeft, ttItem, ref droppedItemParent)) { ttddLeft.Visibility = Visibility.Collapsed; ttddLeft.DetachDetectorElement(); Grid.SetColumn(itcc as UIElement, 0); itccLeft = itcc; ttcLeft = null; if (null == droppedItemParent) { gridContentVertical.Children.Insert(0, itcc as UIElement); } else { droppedItemParent.Children.Add(itcc as UIElement); } } else { (ttcLeftTmp.Parent as Grid).Children.Remove(ttcLeftTmp); gridContentVertical.Children.Insert(0, ttcLeftTmp); } break; case DropLocation.Right: if (ttcRight.Items.Contains(ttItem) && 1 == ttcRight.Items.Count) { return(false); } DetachHandlers(ttcRight); gridContentVertical.Children.Remove(ttcRight); TearableTabControl ttcRightTmp = ttcRight; if (ttcRight == null) { } if (itcc.AddControl(location, ttcRight, ttItem, ref droppedItemParent)) { ttddRight.Visibility = Visibility.Collapsed; ttddRight.DetachDetectorElement(); Grid.SetColumn(itcc as UIElement, 2); itccRight = itcc; ttcRight = null; if (null == droppedItemParent) { gridContentVertical.Children.Insert(0, itcc as UIElement); } else { droppedItemParent.Children.Add(itcc as UIElement); } } else { (ttcRightTmp.Parent as Grid).Children.Remove(ttcRightTmp); gridContentVertical.Children.Insert(0, ttcRightTmp); } break; case DropLocation.Top: case DropLocation.Bottom: case DropLocation.Center: default: throw new NotSupportedException("Center not supported"); } //try //{ // gridContentVertical.Children.Insert(0, itcc as UIElement); //} //catch (Exception ex) //{ //} return(true); }
private void TearableTabControl_ItemsChanged(object sender, NotifyCollectionChangedEventArgs e) { TearableTabControl ttc = sender as TearableTabControl; if (null != ttc) { if (0 == ttc.Items.Count) { DetachHandlers(ttcTop); DetachHandlers(ttcBottom); ttddTop.DetachDetectorElement(); ttddBottom.DetachDetectorElement(); DetachHandlers(ttddTop); DetachHandlers(ttddBottom); if (ttc == ttcTop) { ttcTop = null; if (null != ttcBottom) { gridContentHorizontal.Children.Remove(ttcBottom); TabParent.RemoveControl(this, ttcBottom); ttcBottom = null; } else if (null != itccBottom) { gridContentHorizontal.Children.Remove(itccBottom as UIElement); itccBottom.TabParent = this.TabParent; TabParent.RemoveControl(this, itccBottom as FrameworkElement); itccBottom = null; } else { throw new NullReferenceException("Both tccBottom and itccBottom cannot be null"); } } else if (ttc == ttcBottom) { if (ttcTop?.Items.Count == 0) { } ttcBottom = null; if (null != ttcTop) { gridContentHorizontal.Children.Remove(ttcTop); TabParent.RemoveControl(this, ttcTop); ttcTop = null; } else if (null != itccTop) { gridContentHorizontal.Children.Remove(itccTop as UIElement); itccTop.TabParent = this.TabParent; TabParent.RemoveControl(this, itccTop as FrameworkElement); itccTop = null; } else { throw new NullReferenceException("Both tccTop and itccTop cannot be null"); } } else { throw new NotSupportedException("Child object not supported"); } } } }
public bool AddSplitControl(DropLocation location, DropLocation sourceLoaction, TearableTabItem ttItem) { ITabControlContainer itcc; Grid droppedItemParent = null; switch (location) { case DropLocation.Top: case DropLocation.Bottom: itcc = new TearableTabSplitHorizontal(this); break; case DropLocation.Left: case DropLocation.Right: itcc = new TearableTabSplitVertical(this); break; case DropLocation.Center: default: throw new NotSupportedException("Center not supported"); } tabs[location] = itcc; switch (sourceLoaction) { case DropLocation.Top: if (ttcTop.Items.Contains(ttItem) && 1 == ttcTop.Items.Count) { return(false); } DetachHandlers(ttcTop); gridContentHorizontal.Children.Remove(ttcTop); TearableTabControl ttcTopTmp = ttcTop; if (this.TabParent == null) { } if (ttcTop == null) { // ADE 20210319 return(false); } if (itcc.AddControl(location, ttcTop, ttItem, ref droppedItemParent)) { ttddTop.Visibility = Visibility.Collapsed; ttddTop.DetachDetectorElement(); Grid.SetRow(itcc as UIElement, 0); itccTop = itcc; ttcTop = null; if (null == droppedItemParent) { gridContentHorizontal.Children.Insert(0, itcc as UIElement); } else { droppedItemParent.Children.Add(itcc as UIElement); } } else { (ttcTopTmp.Parent as Grid).Children.Remove(ttcTopTmp); gridContentHorizontal.Children.Insert(0, ttcTopTmp); } break; case DropLocation.Bottom: if (ttcBottom.Items.Contains(ttItem) && 1 == ttcBottom.Items.Count) { return(false); } DetachHandlers(ttcBottom); gridContentHorizontal.Children.Remove(ttcBottom); TearableTabControl ttcBottomTmp = ttcBottom; if (ttcBottom == null) { } if (itcc.AddControl(location, ttcBottom, ttItem, ref droppedItemParent)) { ttddBottom.Visibility = Visibility.Collapsed; ttddBottom.DetachDetectorElement(); Grid.SetRow(itcc as UIElement, 2); itccBottom = itcc; ttcBottom = null; if (null == droppedItemParent) { gridContentHorizontal.Children.Insert(0, itcc as UIElement); } else { droppedItemParent.Children.Add(itcc as UIElement); } } else { (ttcBottomTmp.Parent as Grid).Children.Remove(ttcBottomTmp); gridContentHorizontal.Children.Insert(0, ttcBottomTmp); } break; case DropLocation.Left: case DropLocation.Right: case DropLocation.Center: default: throw new NotSupportedException("Center not supported"); } return(true); }