简体   繁体   English

WPF是否有鼠标滚轮上下滚动事件

[英]Does WPF have mouse wheel scrolling up and down event

I checked msdn.我检查了msdn。 For event related to mouse wheel , there is only one option -- UIElement.MouseWheel对于鼠标滚轮相关的事件,只有一种选择——UIElement.MouseWheel

What I want to do is listening to mouse wheel scrolling forward(up) and backward(down) event.我想要做的是监听鼠标滚轮向前(向上)和向后(向下)滚动事件。

Note: Not clicking the middle wheel button.注意:不要单击中间的滚轮按钮。

No, there is just one event.不,只有一个事件。 When you look at the MouseWheelEventArgs class there is a property Delta.当您查看 MouseWheelEventArgs 类时,有一个属性 Delta。 Delta is positive when the wheel is rotated away from the user and negative when the wheel is rotated toward the user.当滚轮远离用户旋转时,Delta 为正,当滚轮朝向用户旋转时,Delta 为负。

For event related to mouse wheel, there is only one option对于鼠标滚轮相关的事件,只有一种选择

No, there are others.不,还有其他人。

There is also the PreviewMouseWheel ( which functions just like the MouseWheel event and the below code code can be used too ).还有PreviewMouseWheel它的功能就像MouseWheel事件,下面的代码也可以使用)。

The Preview, if needed, has a Delta property too which gives the direction of the wheel.如果需要,预览也有一个Delta属性,它给出了滚轮的方向。

Example例子

private void PreviewMouseWheel(object sender, MouseWheelEventArgs e)
{
    if (e.Delta > 0)
        DoActionUp();

    else if (e.Delta < 0)
        DoActionDown();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM