HandyOrg / HandyOrg/HandyControl

滚动条鼠标滚轮补偿

Open
#1,168 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
7.2k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

  public double MouseWheelDelta
    {
        get { return (double) GetValue(MouseWheelDeltaProperty); }
        set { SetValue(MouseWheelDeltaProperty, value); }
    }

    /// <summary>
    /// 鼠标滚动补偿
    /// </summary>
    public static readonly DependencyProperty MouseWheelDeltaProperty =
        DependencyProperty.Register("MouseWheelDelta", typeof(double), typeof(ScrollViewer), new PropertyMetadata(0d));

    protected override void OnMouseWheel(MouseWheelEventArgs e)
    {
        if (!CanMouseWheel) return;

        var mouseWheelDelta = e.Delta > 0 ? 0 - MouseWheelDelta : 0 + MouseWheelDelta;

        if (!IsInertiaEnabled)
        {
            if (Orientation == Orientation.Vertical)
            {
                base.OnMouseWheel(e);
                this.ScrollToVerticalOffset(this.VerticalOffset + mouseWheelDelta);
            }
            else
            {
                _totalHorizontalOffset = HorizontalOffset;
                CurrentHorizontalOffset = HorizontalOffset;
                _totalHorizontalOffset = Math.Min(Math.Max(0, _totalHorizontalOffset - e.Delta), ScrollableWidth);
                CurrentHorizontalOffset = _totalHorizontalOffset;
                this.ScrollToHorizontalOffset(this.HorizontalOffset + mouseWheelDelta);
            }
            return;
        }
        e.Handled = true;

        if (Orientation == Orientation.Vertical)
        {
            if (!_isRunning)
            {
                _totalVerticalOffset = VerticalOffset;
                CurrentVerticalOffset = VerticalOffset;
            }
            _totalVerticalOffset = Math.Min(Math.Max(0, _totalVerticalOffset - e.Delta), ScrollableHeight);
            ScrollToVerticalOffsetWithAnimation(_totalVerticalOffset+ mouseWheelDelta);
        }
        else
        {
            if (!_isRunning)
            {
                _totalHorizontalOffset = HorizontalOffset;
                CurrentHorizontalOffset = HorizontalOffset;
            }
            _totalHorizontalOffset = Math.Min(Math.Max(0, _totalHorizontalOffset - e.Delta), ScrollableWidth);
            ScrollToHorizontalOffsetWithAnimation(_totalHorizontalOffset+ mouseWheelDelta);
        }
    }

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the WPF ScrollViewer implementation and its OnMouseWheel entry point, then compare the requested MouseWheelDelta behavior for vertical and horizontal scrolling. Done should be defined as consistent compensation behavior across the non-inertia and inertia paths shown in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
desktop
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.