Skip to content

Add Horizontal MouseWheel Scrolling Support #5937

Closed as not planned
Closed as not planned

Description

@aquinn39

Currently, MouseWheel events are only sent in response to vertical mouse wheel scrolling; no event is sent for horizontal scrolling despite Windows sending a window message in response to horizontal mouse/touchpad scrolling. This means that horizontal scrolling does nothing in WPF apps, unless the app manually listens for and interprets the horizontal mouse wheel event and responds to it manually.

Activity

  1. lindexi commented on Jan 12, 2022

    @lindexi
    Member
            private IntPtr Hook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
            {
                const int WM_MOUSEHWHEEL = 0x020E;
                switch (msg)
                {
                    case WM_MOUSEHWHEEL:
                        int tilt = (short) HIWORD(wParam);
                        OnMouseTilt(tilt);
                        return (IntPtr) 1;
                }
                return IntPtr.Zero;
            }
    
            private static int HIWORD(IntPtr ptr)
            {
                var val32 = ptr.ToInt32();
                return ((val32 >> 16) & 0xFFFF);
            }
    
            private void OnMouseTilt(int tilt)
            {
                // Your code
               
            }
  2. added
    Enhancement Requested
    and removed on Jan 12, 2022
  3. added this to the Future milestone on Jan 12, 2022
  4. self-assigned this
    on Jan 12, 2022
  5. Symbai commented on May 9, 2023

    @Symbai
    Contributor

    I was going to request the same. WPF doesnt support scrolling horizontally using "mouse" devices only. Not via mouse wheel (including the classic mouse wheel with up/down, but there are also mouse wheels which you can move to left or right), and not via touchpad.

    There are some "hacks" to achieve that:
    https://blog.walterlv.com/post/handle-horizontal-scrolling-of-touchpad-en.html
    https://stackoverflow.com/questions/4158101/how-to-horizontally-scroll-in-wpf-using-mouse-tilt-wheel
    https://stackoverflow.com/questions/54549047/shift-mouse-wheel-to-scroll-horizontally (using Shift + a classic mouse wheel works fine in for example Microsoft Edge)

    But this feels like it should be implemented into WPF by default. @lindexi The workaround you mention, just like the other hacks, are really annoying to implement. You'd have to do that for every control which has scroll support in every page of your application.

  6. lindexi commented on May 9, 2023

    @lindexi
    Member

    @Symbai Do you thank adding the new event or adding to existing event is better?

  7. Symbai commented on May 9, 2023

    @Symbai
    Contributor

    @lindexi It is unclear to me how using MOUSEWHEEL hook tells us if it scrolls horizontal and not vertical. Imagine a scrollviewer where BOTH scrollbars are shown at the same time and the user uses a touchpad for example. He can scroll up/down but also left/right. So what exactly is sent to the application in both cases, where does it differ and how to other frameworks react on this. (WM_MOUSEHWHEEL is not the same as WM_MOUSEWHEEL)

    Adding to existing public events would be a breaking change. So I agree with #3201 that it should add a new public event.

    Also it seems that this request has another open issue with some ideas of how to implement: #3201

    Maybe its worth it to merge both.

    As for the SHIFT + mouse wheel. I just used this workaround (Creating a new class inheriting the ScrollViewer, overridding the OnMouseWheel event. At least this wouldn't cause any public surface changes. I think that we should probably add this separately. One PR adds the SHIFT + scroll support (which can be done already) and a second PR should be made for WM_MOUSEHWHEEL hook (which takes longer as it adds new public events and we must discuss the names etc)

  8. miloush commented on May 9, 2023

    @miloush
    Contributor

    Adding to existing public events would be a breaking change.

    How?

  9. Symbai commented on May 9, 2023

    @Symbai
    Contributor

    Adding to existing public events would be a breaking change.

    How?

    Because the existing wheel change event has no indicator if its about horizontal or vertical. Adding such an indicator like a boolean forces developers to check that. Existing code wouldn't check that, so it breaks.

  10. miloush commented on May 9, 2023

    @miloush
    Contributor

    You could add a different property carrying the horizontal value only, for example HorizontalDelta, so that the existing applications are not affected.

    The convincing argument in #3201 for this to be separate event is that it comes as a separate event from the Window subsystem.

    I am in favor of closing this as duplicate of #3201

  11. aquinn39 commented on May 9, 2023

    @aquinn39
    Author

    Closing this as a duplicate of #3201.

  12. ghost removed this from the Future milestone on May 9, 2023
  13. Symbai commented on May 9, 2023

    @Symbai
    Contributor

    Instead of closing you should have merged posts. And nobody said anything to my suggestion about making a separate PR for shift + mouse wheel support.... the "duplicate" doesn't cover this.

    @miloush: This still break existing code as you don't know what developers are doing in this event. They could be calling another method regardless of the delta value. And right now it is SAFE that its only for vertical scrolling.

  14. aquinn39 commented on May 9, 2023

    @aquinn39
    Author

    Instead of closing you should have merged posts. And nobody said anything to my suggestion about making a separate PR for shift + mouse wheel support.... the "duplicate" doesn't cover this.

    @miloush: This still break existing code as you don't know what developers are doing in this event. They could be calling another method regardless of the delta value. And right now it is SAFE that its only for vertical scrolling.

    I am happy to merge the issues, I just don’t know how. If I can figure out how to merge it, I’ll reopen and merge it.

  15. miloush commented on May 9, 2023

    @miloush
    Contributor

    shift + mouse wheel support

    That is not a standard Windows behavior and I would need some convincing to support it out of the box. It doesn't work like that in Notepad/Paint/native controls, Word (it does in VS or Adobe Reader). It's Ctrl+Shift+Scroll for Excel, Ctrl+Scroll in Illustrator/Photoshop etc. Windows Explorer scrolls horizontally using normal scrolling if there is horizontal scrollbar only.

  16. ghost locked as resolved and limited conversation to collaborators on Jun 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Enhancement Requested

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions