如何使用鼠标倾斜滚轮在 WPF 中水平滚动?

如何使用鼠标倾斜滚轮在 WPF 中水平滚动?

问题描述:

如何让 WPF 使用鼠标倾斜滚轮响应水平滚动?例如,我有一个 Microsoft Explorer 迷你鼠标,并尝试使用

How do you enable WPF to respond to horizontal scrolling using the mouse tilt wheel? For example, I have a Microsoft Explorer mini mouse and have tried horizontally scrolling content contained within a ScrollViewer with

HorizontalScrollBarVisibility="Visible"

但内容不会水平滚动.但是,垂直滚动可以像往常一样可靠地工作.

but the content will not scroll horizontally. Vertical scrolling, however, works reliably as usual.

如果此时 WPF 不直接支持此类输入,是否可以通过与非托管代码互操作来执行此操作?

If such input is not directly supported by WPF at this time, is there a way to do this using interop with unmanaged code?

谢谢!

在您的 Window 构造函数中调用 AddHook() 方法,以便您可以监视消息.查找 WM_MOUSEHWHEEL,消息 0x20e.使用 wParam.ToInt32() >> 16 得到移动量,120 的倍数.

Call the AddHook() method in your Window constructor so you can spy on the messages. Look for WM_MOUSEHWHEEL, message 0x20e. Use wParam.ToInt32() >> 16 to get the movement amount, a multiple of 120.