示例#1
0
        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.
                }
                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;
            }
        }
        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;
                }
            }
        }