Skip to content

Commit d18dd3e

Browse files
authored
Restricts horizontal scrolling to mouse over (#3953)
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.
1 parent 1a307de commit d18dd3e

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

src/MaterialDesignThemes.Wpf/ScrollViewerAssist.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,18 +140,13 @@ IntPtr Hook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled
140140
const int WM_MOUSEHWHEEL = 0x020E;
141141
switch (msg)
142142
{
143-
case WM_MOUSEHWHEEL:
143+
case WM_MOUSEHWHEEL when scrollViewer.IsMouseOver:
144144
int tilt = (short)((wParam.ToInt64() >> 16) & 0xFFFF);
145-
OnMouseTilt(tilt);
145+
scrollViewer.ScrollToHorizontalOffset(scrollViewer.HorizontalOffset + tilt);
146146
return (IntPtr)1;
147147
}
148148
return IntPtr.Zero;
149149
}
150-
151-
void OnMouseTilt(int tilt)
152-
{
153-
scrollViewer.ScrollToHorizontalOffset(scrollViewer.HorizontalOffset + tilt);
154-
}
155150
}
156151
}
157152

0 commit comments

Comments
 (0)