如何处理WPF中的鼠标滚轮点击事件?
问题描述:
当鼠标滚轮被点击时,我想在标签控件中关闭一个标签页。如何在WPF中捕获此事件?
I want to close a tab in my tab control when the mouse wheel is clicked. How can I capture this event in WPF?
编辑:
以下是代码:
Here's the code:
private void tabMain_MouseDown(object sender, MouseButtonEventArgs e)
{
if(e.ChangedButton == MouseButton.Middle && e.ButtonState == MouseButtonState.Pressed)
{
MessageBox.Show("Middle button clicked");
}
}
答
Mousewheel实际上是MiddleButton,所以Wheel点击MouseDown事件的条件是 ChangedButton == Middle&& ButtonState ==已按
Mousewheel is actually the MiddleButton, So the condition for Wheel click on a MouseDown event is ChangedButton == Middle && ButtonState == Pressed