private object CreateSingularTab(SoheilEntityType type) { Cursor openhand = new System.Windows.Input.Cursor(System.IO.Path.Combine(Environment.CurrentDirectory, "Images\\openhand.cur")); Cursor closehand = new System.Windows.Input.Cursor(System.IO.Path.Combine(Environment.CurrentDirectory, "Images\\closehand.cur")); object itemToAdd = new SoheilSingularView(SingularList, AccessList, openhand, closehand); Interlocked.Increment(ref _newTabNumber); itemToAdd = new ChromeTabItem { Header = GetTabHeader(type), Content = itemToAdd, Tag = type }; return itemToAdd; }
internal int GetTabIndex(ChromeTabItem item) { for (int i = 0; i < Items.Count; i += 1) { ChromeTabItem tabItem = AsTabItem(Items[i]); if (tabItem == item) { return i; } } return -1; }
private object CreateSplitTab(SoheilEntityType type) { object itemToAdd = new SoheilSplitView(SplitList, AccessList); Interlocked.Increment(ref _newTabNumber); itemToAdd = new ChromeTabItem { Header = GetTabHeader(type), Content = itemToAdd, Tag = type }; return itemToAdd; }
internal void ChangeSelectedItem(ChromeTabItem item) { int index = GetTabIndex(item); if (index > -1) { if (SelectedItem != null) { Panel.SetZIndex(AsTabItem(SelectedItem), 0); } SelectedIndex = index; Panel.SetZIndex(item, 1001); } }
private static void Reanimate(ChromeTabItem tab, double left, double duration, Action completed) { if (tab == null) { return; } var offset = new Thickness(left, 0, -left, 0); var moveBackAnimation = new ThicknessAnimation(tab.Margin, offset, new Duration(TimeSpan.FromSeconds(duration))); Storyboard.SetTarget(moveBackAnimation, tab); Storyboard.SetTargetProperty(moveBackAnimation, new PropertyPath(MarginProperty)); var sb = new Storyboard(); sb.Children.Add(moveBackAnimation); sb.Completed += (o, ea) => { sb.Remove(); if (completed != null) { completed(); } }; sb.Begin(); }
private static void StickyReanimate(ChromeTabItem tab, double left, double duration) { Action completed = () => { tab.Margin = new Thickness(left, 0, -left, 0); }; Reanimate(tab, left, duration, completed); }
protected override void OnPreviewMouseLeftButtonUp(MouseButtonEventArgs e) { base.OnPreviewMouseLeftButtonUp(e); _draggingWindow = false; if (_addButtonRect.Contains(e.GetPosition(this)) && _addButton.Background == _hoverBrush) { _addButton.Background = null; InvalidateVisual(); if (_addButton.Visibility == Visibility.Visible) { //ParentTabControl.AddTab(new Label(), true); // HACK: Do something with default templates, here. } return; } if (IsMouseCaptured) { Mouse.Capture(null); double offset = 0; if (_slideIndex < _originalIndex + 1) { offset = _slideIntervals[_slideIndex + 1] - 2*_currentTabWidth/3 + _overlap; } else if (_slideIndex > _originalIndex + 1) { offset = _slideIntervals[_slideIndex - 1] + 2*_currentTabWidth/3 - _overlap; } Console.WriteLine(offset); Action completed = () => { if (_draggedTab != null) { ParentTabControl.ChangeSelectedItem(_draggedTab); _draggedTab.Margin = new Thickness(offset, 0, -offset, 0); _draggedTab = null; _captureGuard = 0; ParentTabControl.MoveTab(_originalIndex, _slideIndex - 1); } }; Reanimate(_draggedTab, offset, .1, completed); } else { if (_draggedTab != null) { ParentTabControl.ChangeSelectedItem(_draggedTab); _draggedTab.Margin = new Thickness(0); } _draggedTab = null; _captureGuard = 0; } }
protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e) { base.OnPreviewMouseLeftButtonDown(e); _slideIntervals = null; if (_addButtonRect.Contains(e.GetPosition(this))) { _addButton.Background = _hoverBrush; InvalidateVisual(); return; } _downPoint = e.GetPosition(this); HitTestResult result = VisualTreeHelper.HitTest(this, _downPoint); if (result == null) { return; } DependencyObject source = result.VisualHit; while (source != null && !Children.Contains(source as UIElement)) { source = VisualTreeHelper.GetParent(source); } if (source == null) { return; } _draggedTab = source as ChromeTabItem; if (_draggedTab != null && Children.Count > 1) { SetZIndex(_draggedTab, 1000); } else if (_draggedTab != null && Children.Count == 1) { _draggingWindow = true; Window window = Window.GetWindow(this); if (window != null) window.DragMove(); } }