Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forward pointer wheel event from scrollbar to scrollviewer #16398

Merged
merged 4 commits into from
Aug 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/Avalonia.Controls/Primitives/ScrollBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 257,27 @@ protected override void OnKeyDown(KeyEventArgs e)
}
}

protected override void OnPointerWheelChanged(PointerWheelEventArgs e)
{
base.OnPointerWheelChanged(e);

// We need to handle pointer wheel event to allow scrolling with the pointer wheel. So we raise the event on the scrollviewer's presenter
if (!e.Handled && _owner?.Presenter is { } presenter && VisualRoot is Visual root)
{
e.Handled = true;
e = new PointerWheelEventArgs(
this,
e.Pointer,
root,
e.GetPosition(root),
e.Timestamp,
new PointerPointProperties((RawInputModifiers)e.KeyModifiers, PointerUpdateKind.Other),
e.KeyModifiers,
e.Delta);
presenter.RaiseEvent(e);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By re-raising the same RoutedEventArgs, this will change the observable RoutedEventArgs.Source and Route, so parent listeners will have wrong information to act on (e.g. Tunnel mode in a middle of a Bubble).

I think a copy of the event should be raised instead to avoid this.

The original event probably needs to be marked as handled if the copy is handled.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update done.

}
}

protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
{
base.OnPropertyChanged(change);
Expand Down
Loading