From 6ba52dc5bf7da0148eb2f46143e03ccb9b45c3d9 Mon Sep 17 00:00:00 2001 From: Kevin Bost Date: Sun, 26 Oct 2025 10:48:21 -0700 Subject: [PATCH] Restricts horizontal scrolling to mouse over Ensures horizontal mouse wheel events only affect the ScrollViewer when the mouse cursor is directly over it. This prevents unintended scrolling of background or non-focused elements. Simplifies the scroll handling by inlining the logic and removing a redundant helper method. --- src/MaterialDesignThemes.Wpf/ScrollViewerAssist.cs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/MaterialDesignThemes.Wpf/ScrollViewerAssist.cs b/src/MaterialDesignThemes.Wpf/ScrollViewerAssist.cs index b360bf1605..2bfa6a398a 100644 --- a/src/MaterialDesignThemes.Wpf/ScrollViewerAssist.cs +++ b/src/MaterialDesignThemes.Wpf/ScrollViewerAssist.cs @@ -140,18 +140,13 @@ IntPtr Hook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled const int WM_MOUSEHWHEEL = 0x020E; switch (msg) { - case WM_MOUSEHWHEEL: + case WM_MOUSEHWHEEL when scrollViewer.IsMouseOver: int tilt = (short)((wParam.ToInt64() >> 16) & 0xFFFF); - OnMouseTilt(tilt); + scrollViewer.ScrollToHorizontalOffset(scrollViewer.HorizontalOffset + tilt); return (IntPtr)1; } return IntPtr.Zero; } - - void OnMouseTilt(int tilt) - { - scrollViewer.ScrollToHorizontalOffset(scrollViewer.HorizontalOffset + tilt); - } } }