From 4c2d9fcda7bb703600e4146cefb790c5cbbb3bb6 Mon Sep 17 00:00:00 2001 From: Emmanuel Hansen Date: Thu, 1 Aug 2024 22:31:40 +0000 Subject: [PATCH] Forward pointer wheel event from scrollbar to scrollviewer (#16398) * forward pointer wheel event from scrollbar to scrollviewer * raise cloned pointer wheel event in scrollbar --------- Co-authored-by: Max Katz --- src/Avalonia.Controls/Primitives/ScrollBar.cs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/Avalonia.Controls/Primitives/ScrollBar.cs b/src/Avalonia.Controls/Primitives/ScrollBar.cs index 83e5de4dbe..7df7012f8f 100644 --- a/src/Avalonia.Controls/Primitives/ScrollBar.cs +++ b/src/Avalonia.Controls/Primitives/ScrollBar.cs @@ -257,6 +257,27 @@ namespace Avalonia.Controls.Primitives } } + 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); + } + } + protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change) { base.OnPropertyChanged(change);