internal void StartTabDrag(Point p, ChromeTabItem tab = null, bool isTabGrab = false) { this._lastMouseDown = DateTime.UtcNow; if (tab == null) { HitTestResult result = VisualTreeHelper.HitTest(this, this.downPoint); if (result == null) { return; } DependencyObject source = result.VisualHit; while (source != null && !this.Children.Contains(source as UIElement)) { source = VisualTreeHelper.GetParent(source); } if (source == null) { //The mouse is not over a tab item, so just return. return; } this.draggedTab = source as ChromeTabItem; } else if (tab != null) { this.draggedTab = tab; } else { return; } if (this.draggedTab != null) { if (this.Children.Count == 1 && ParentTabControl.DragWindowWithOneTab && Mouse.LeftButton == MouseButtonState.Pressed && !isTabGrab) { this.draggingWindow = true; Window.GetWindow(this).DragMove(); } else { this.downTabBoundsPoint = MouseUtilities.CorrectGetPosition(this.draggedTab); Canvas.SetZIndex(this.draggedTab, 1000); ParentTabControl.ChangeSelectedItem(this.draggedTab); if (isTabGrab) { for (int i = 0; i < this.Children.Count; i++) { ProcessMouseMove(new Point(p.X + 0.1, p.Y)); } } else { ProcessMouseMove(new Point(p.X + 0.1, p.Y)); } } } }
protected override void OnKeyDown(KeyEventArgs e) { base.OnKeyDown(e); if (e.Key == Key.Enter || e.Key == Key.Space || e.Key == Key.Return) { ParentTabControl.ChangeSelectedItem(this); } }
protected override void OnPreviewMouseLeftButtonUp(MouseButtonEventArgs e) { base.OnPreviewMouseLeftButtonUp(e); this.draggingWindow = false; if (this.addButtonRect.Contains(e.GetPosition(this)) && this.addButton.Background == Brushes.DarkGray) { this.addButton.Background = null; this.InvalidateVisual(); if (this.addButton.Visibility == Visibility.Visible) { //ParentTabControl.AddTab(new Label(), true); // HACK: Do something with default templates, here. //AddTabClick(); ParentTabControl.RerouteAddTabClick(); } return; } if (this.IsMouseCaptured) { Mouse.Capture(null); double offset = 0; if (this.slideIndex < this.originalIndex + 1) { offset = this.slideIntervals[this.slideIndex + 1] - 2 * this.currentTabWidth / 3 + this.overlap; } else if (this.slideIndex > this.originalIndex + 1) { offset = this.slideIntervals[this.slideIndex - 1] + 2 * this.currentTabWidth / 3 - this.overlap; } Console.WriteLine(offset); Action completed = () => { if (this.draggedTab != null) { ParentTabControl.ChangeSelectedItem(this.draggedTab); this.draggedTab.Margin = new Thickness(offset, 0, -offset, 0); this.draggedTab = null; this.captureGuard = 0; ParentTabControl.MoveTab(this.originalIndex, this.slideIndex - 1); } }; Reanimate(this.draggedTab, offset, .1, completed); } else { if (this.draggedTab != null) { ParentTabControl.ChangeSelectedItem(this.draggedTab); this.draggedTab.Margin = new Thickness(0); } this.draggedTab = null; this.captureGuard = 0; } }
protected override void OnInitialized(EventArgs e) { base.OnInitialized(e); this.SetTabItemsOnTabs(); if (Children.Count > 0) { if (Children[0] is ChromeTabItem) { ParentTabControl.ChangeSelectedItem(Children[0] as ChromeTabItem); } } }
protected override void OnInitialized(EventArgs e) { base.OnInitialized(e); this.SetTabItemsOnTabs(); if (Children.Count > 0) { if (Children[0] is ChromeTabItem) { ParentTabControl.ChangeSelectedItem(Children[0] as ChromeTabItem); } } if (ParentTabControl != null && ParentTabControl.AddButtonTemplate != null) { SetAddButtonControlTemplate(ParentTabControl.AddButtonTemplate); } }
internal void StartTabDrag(Point p, ChromeTabItem tab = null, bool isTabGrab = false) { this._lastMouseDown = DateTime.UtcNow; if (tab == null) { tab = GetTabFromMousePosition(this.downPoint); } if (tab != null) { this.draggedTab = tab; } else { //The mouse is not over a tab item, so just return. return; } if (this.draggedTab != null) { if (this.Children.Count == 1 && ParentTabControl.DragWindowWithOneTab && Mouse.LeftButton == MouseButtonState.Pressed && !isTabGrab) { this.draggingWindow = true; Window.GetWindow(this).DragMove(); } else { this.downTabBoundsPoint = MouseUtilities.CorrectGetPosition(this.draggedTab); Canvas.SetZIndex(this.draggedTab, 1000); ParentTabControl.ChangeSelectedItem(this.draggedTab); if (isTabGrab) { for (int i = 0; i < this.Children.Count; i++) { ProcessMouseMove(new Point(p.X + 0.1, p.Y)); } } } } }
private void OnTabRelease(Point p, bool closeTabOnRelease, double animationDuration = stickyReanimateDuration) { lock (_lockObject) { this.draggingWindow = false; if (ParentTabControl.IsAddButtonVisible) { if (this.addButtonRect.Contains(p) && this.addButton.Background == Brushes.DarkGray) { this.addButton.Background = null; this.InvalidateVisual(); if (this.addButton.Visibility == Visibility.Visible) { ParentTabControl.AddTab(); } return; } } if (this.IsMouseCaptured) { this.ReleaseMouseCapture(); double offset = 0; if (this.slideIntervals != null) { if (this.slideIndex < this.originalIndex + 1) { offset = this.slideIntervals[this.slideIndex + 1] - GetWidthForTabItem(this.draggedTab) * (1 - tabWidthSlidePercent) + this.overlap; } else if (this.slideIndex > this.originalIndex + 1) { offset = this.slideIntervals[this.slideIndex - 1] + GetWidthForTabItem(this.draggedTab) * (1 - tabWidthSlidePercent) - this.overlap; } } int localSlideIndex = this.slideIndex; Action completed = () => { if (this.draggedTab != null) { ParentTabControl.ChangeSelectedItem(this.draggedTab); object vm = this.draggedTab.Content; this.draggedTab.Margin = new Thickness(offset, 0, -offset, 0); this.draggedTab = null; this.captureGuard = 0; ParentTabControl.MoveTab(this.originalIndex, localSlideIndex - 1); this.slideIntervals = null; this.addButton.Visibility = System.Windows.Visibility.Visible; _hideAddButton = false; this.InvalidateVisual(); if (closeTabOnRelease && ParentTabControl.CloseTabCommand != null) { Debug.WriteLine("sendt close tab command"); ParentTabControl.CloseTabCommand.Execute(vm); } if (this.Children.Count > 1) { //this fixes a bug where sometimes tabs got stuck in the wrong position. RealignAllTabs(); } } }; Reanimate(this.draggedTab, offset, animationDuration, completed); } else { if (this.draggedTab != null) { ParentTabControl.ChangeSelectedItem(this.draggedTab); this.draggedTab.Margin = new Thickness(0); } this.draggedTab = null; this.captureGuard = 0; this.slideIntervals = null; } } }