Пример #1
0
 public bool TryMoveUp(Rect rect)
 {
     if (_screenDataRowIndex < AxisYConverter.ToData(_startPoint.Y)) // 不在位置 0 (第一笔)
     {
         _startPoint   = new Point(rect.X, rect.Y <= 0 ? 0 : rect.Y - rect.Height);
         _currentPoint = new Point(rect.X + rect.Width, _startPoint.Y);
         return(true);
     }
     return(false);
 }
Пример #2
0
        protected override void OnParentKeyDown(object sender, KeyEventArgs e)
        {
            if (Keyboard.Modifiers == ModifierKeys.Shift)
            {
                return;
            }

            if (InitalDrawLocation == null)
            {
                return;
            }

            _screenDataRowIndex = AxisPanel.GetScreenTopRowIndex();
            var prevRowIndex = AxisYConverter.ToData(InitalDrawLocation.Value.Y);

            switch (e.Key)
            {
            case Key.Left:
                MoveLeft(InitalDrawLocation.Value);
                MeasureDragingArea(_screenDataRowIndex);
                e.Handled = 0 <= ConvertToRelativePosition(_startPoint).X;
                break;

            case Key.Right:
                if (TryMoveRight(InitalDrawLocation.Value))
                {
                    MeasureDragingArea(_screenDataRowIndex);
                }
                e.Handled = ConvertToRelativePosition(_currentPoint).X <= RenderSize.Width;
                break;

            case Key.Up:
                TryMoveUp(InitalDrawLocation.Value);
                var moveUpRowIndex = AxisYConverter.ToData(_startPoint.Y);
                e.Handled = moveUpRowIndex != prevRowIndex;
                if (!e.Handled)
                {
                    _screenDataRowIndex -= _screenDataRowIndex > 0 ? 1 : 0;     // scroll up occurred
                }
                MeasureDragingArea(_screenDataRowIndex);
                break;

            case Key.Down:
                TryMoveDown(InitalDrawLocation.Value);
                var moveDownRowIndex = AxisYConverter.ToData(_startPoint.Y);

                if ((RenderSize.Height - AxisYConverter.DataToScreen(moveDownRowIndex)) < Interval)     // 屏幕最后一格未满
                {
                    e.Handled = false;
                }
                else
                {
                    e.Handled = moveDownRowIndex != prevRowIndex;
                }

                MeasureDragingArea(_screenDataRowIndex);

                if (!e.Handled)
                {
                    _screenDataRowIndex += GetItemsSourceCount() - 1 <= moveDownRowIndex ? 0 : 1;     // scroll down occurred
                }
                break;

            default:
                ClickCount = 0;
                break;
            }

            SetInitalDrawLocation();

            if (e.Handled)
            {
                InvalidateVisual(); //未发生scroll bar 卷动, 手动刷新 cell 新的位置
            }
            else
            {
                LayerContainer.Focus();
            }
            // e.Handled 如果为 false 代表由 scroll bar 滚动来引发重绘
        }