Reputation: 11111
I want to close a tab in my tab control when the mouse wheel is clicked. How can I capture this event in WPF?
EDIT: 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");
}
}
Upvotes: 15
Views: 17028
Reputation: 1
In case someone is trying to catch this event but fails, check if sender has mouse gestures "intercepting" and handling it before it reaches MouseDown event.
Here is my situation with HelixViewport3D from HelixTookit library. MouseWheelDown is caught in MouseDown event only after i nullify following gesture:
myHelixPort.PanGesture2 = new MouseGesture(MouseAction.None);
Hope it'll save you some time.
Upvotes: 0
Reputation: 3863
An even easier solution
if (e.MiddleButton) { MessageBox.Show("Middle button clicked"); }
Upvotes: 3
Reputation: 50048
Mousewheel is actually the MiddleButton, So the condition for Wheel click on a MouseDown event is ChangedButton == Middle && ButtonState == Pressed
Upvotes: 19