Exemplo n.º 1
0
        void OnPointerReleased(object sender, PointerRoutedEventArgs e)
        {
            if (e.IsTouch())
            {
                // 触摸模式只支持列排序
                if (_pointerID == e.Pointer.PointerId)
                {
                    ReleasePointerCapture(e.Pointer);
                    _pointerID = null;
                    ChangedSortState();
                }
                return;
            }

            if (_isDragging)
            {
                if (_dragTgtCol != null)
                {
                    // 拖拽结束
                    _owner.FinishedDrag();
                    Cols cols  = _owner.Lv.Cols;
                    int  index = cols.IndexOf(_dragTgtCol);
                    cols.Remove(Col);
                    cols.Insert(index, Col);
                    cols.Invalidate();
                }
                else
                {
                    // 列排序
                    ChangedSortState();
                }
            }
            ResetMouseState();
        }
Exemplo n.º 2
0
 void OnPointerMoved(object sender, PointerRoutedEventArgs e)
 {
     // 触摸模式滚动
     if (e.IsTouch() && _pointerID == e.Pointer.PointerId)
     {
         Point cur = e.GetCurrentPoint(null).Position;
         _owner.DoHorScroll(cur.X - _ptLast.X);
         _ptLast  = cur;
         _isMoved = true;
     }
 }
Exemplo n.º 3
0
        void OnPointerMoved(object sender, PointerRoutedEventArgs e)
        {
            e.Handled = true;
            if (e.IsTouch())
            {
                // 触摸模式只支持列排序
                if (_pointerID == e.Pointer.PointerId)
                {
                    ReleasePointerCapture(e.Pointer);
                    _pointerID = null;
                }
                return;
            }

            // 鼠标未按下时的滑过
            if (!_isDragging && _resizingCol == null)
            {
                Point pt = e.GetCurrentPoint(this).Position;
                if (pt.X >= _resizePadding && Col.Width - pt.X >= _resizePadding)
                {
                    SetCursor(CoreCursorType.Arrow);
                    VisualStateManager.GoToState(this, "PointerOver", true);
                }
                else
                {
                    SetCursor(CoreCursorType.SizeWestEast);
                    VisualStateManager.GoToState(this, "Normal", true);
                }
                return;
            }

            // 调整列宽
            if (_resizingCol != null)
            {
                Point  cur   = e.GetCurrentPoint(null).Position;
                double width = _resizingCol.Width + cur.X - _ptLast.X;
                if (width > 35)
                {
                    // 最小宽度能显示一个字
                    _resizingCol.Width = width;
                    _owner.Lv.Cols.Invalidate();
                    _ptLast = cur;
                }
                return;
            }

            // 拖拽列
            _dragTgtCol = _owner.GetDragTargetCol(Col, e.GetCurrentPoint(_owner).Position.X);
        }
Exemplo n.º 4
0
        void OnPointerPressed(object sender, PointerRoutedEventArgs e)
        {
            if (!CapturePointer(e.Pointer))
            {
                return;
            }

            e.Handled = true;
            if (e.IsTouch())
            {
                // 触摸模式只支持列排序
                _pointerID = e.Pointer.PointerId;
                return;
            }

            // 鼠标模式
            Point pt = e.GetCurrentPoint(this).Position;

            if (pt.X < _resizePadding)
            {
                // 左侧调列宽
                _resizingCol = GetLeftCol();
                if (_resizingCol == null)
                {
                    _isDragging = true;
                    SetCursor(CoreCursorType.Arrow);
                    VisualStateManager.GoToState(this, "Pressed", true);
                }
                else
                {
                    _ptLast = e.GetCurrentPoint(null).Position;
                    VisualStateManager.GoToState(this, "Normal", true);
                }
            }
            else if (pt.X > Col.Width - _resizePadding)
            {
                // 右侧调列宽
                _resizingCol = Col;
                _ptLast      = e.GetCurrentPoint(null).Position;
                VisualStateManager.GoToState(this, "Normal", true);
            }
            else
            {
                // 开始拖拽
                _isDragging = true;
                VisualStateManager.GoToState(this, "Pressed", true);
            }
        }
Exemplo n.º 5
0
        protected override void OnPointerEntered(PointerRoutedEventArgs e)
        {
            // 触摸时不自动打开下级菜单
            if (Owner == null || Kit.IsPhoneUI || e.IsTouch())
            {
                return;
            }

            IsMouseOver = true;
            ChangeState(MenuItemState.PointerOver);

            // 一级菜单且已有选择项
            if (ParentMi == null)
            {
                if ((Owner.SelectedMi != null && Owner.SelectedMi != this) ||
                    Owner.IsContextMenu)
                {
                    IsSelected = true;
                    if (Items.Count > 0)
                    {
                        OpenSubMenu();
                    }
                }
                return;
            }

            // 子菜单
            if (IsSubmenuOpen)
            {
                IsSelected = true;
            }
            else if (Items.Count > 0)
            {
                if (ParentMi.SelectedMi == null)
                {
                    IsSelected = true;
                }
                OpenSubMenu();
            }
            else
            {
                IsSelected = true;
            }
        }
Exemplo n.º 6
0
        void OnPointerMoved(object sender, PointerRoutedEventArgs e)
        {
            if (_pointerID != e.Pointer.PointerId)
            {
                return;
            }

            // 允许有短距离移动
            e.Handled = true;
            Point cur = e.GetCurrentPoint(null).Position;

            if (Math.Abs(cur.X - _ptLast.X) > 4 || Math.Abs(cur.Y - _ptLast.Y) > 4)
            {
                ReleasePointerCapture(e.Pointer);
                _pointerID = null;
                if (e.IsTouch())
                {
                    _rcPointer.Fill = null;
                }
            }
        }
Exemplo n.º 7
0
        protected override void OnPointerExited(PointerRoutedEventArgs e)
        {
            if (e.IsTouch())
            {
                ChangeState(MenuItemState.Normal);
                return;
            }

            IsMouseOver = false;
            bool unselect = ((ParentMi == null && Items.Count > 0 && !IsSubmenuOpen) ||
                             (ParentMi != null && (Items.Count == 0 || !IsSubmenuOpen)));

            if (unselect && IsSelected)
            {
                IsSelected = false;
            }
            else
            {
                ChangeState(MenuItemState.Normal);
            }
        }