Skip to content

Commit 6ba52dc

Browse files
committed
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.
1 parent b19d824 commit 6ba52dc

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)