Exemplo n.º 1
0
        protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            base.OnPreviewMouseLeftButtonDown(e);

            lock (_mutex)
            {
                if (ParentTabControl == null || ParentTabControl.Items.Count <= 1 || !ParentTabControl.CanMoveTabs)
                {
                    return;
                }

                _startPos = e.GetPosition(this);
                var tab = GetTabItem(_startPos);
                if (tab == null)
                {
                    return;
                }

                _tabStatuses   = null;
                tab.IsSelected = true;

                var draggedTabInsidePos = TranslatePoint(_startPos, tab);
                _minMoveX = draggedTabInsidePos.X + tab.Margin.Left;
                _maxMoveX = this.ActualWidth - tab.ActualWidth + draggedTabInsidePos.X;

                _draggedTab = tab;

                this.CaptureMouse();
            }
        }
Exemplo n.º 2
0
        protected override void OnPreviewMouseLeftButtonUp(MouseButtonEventArgs e)
        {
            base.OnPreviewMouseLeftButtonUp(e);

            if (_draggedTab == null)
            {
                return;
            }

            if (_draggedTab.IsDragging)
            {
                _draggedTab.StopDragging();
                bool isFound            = false;
                int  draggedTabNewIndex = -1;
                for (int i = 0; i < ParentTabControl.Items.Count; i++)
                {
                    if (!isFound)
                    {
                        if (_tabStatuses[i].IsChanged)
                        {
                            isFound            = true;
                            draggedTabNewIndex = i;
                        }
                    }
                    else
                    {
                        if (draggedTabNewIndex > _draggedTab.Index && _tabStatuses[i].IsChanged)
                        {
                            draggedTabNewIndex = i;
                        }
                    }

                    var tabItem = ParentTabControl.ItemContainerGenerator.ContainerFromIndex(i) as TabItemEx;
                    Animations.TranslateX(tabItem, 0, _timeSpanZero);
                }

                if (isFound)
                {
                    ParentTabControl.MoveItem(_draggedTab.Index, draggedTabNewIndex);
                }
            }

            this.ReleaseMouseCapture();
            _draggedTab = null;
        }
Exemplo n.º 3
0
 public ClosingItemEventArgs(TabItemEx tabItem, object item)
 {
     TabItemEx = tabItem;
     Item      = item;
 }