In Google Chrome I really like the functionality of the left mouse hold down on the Back button to get the full browse history.
In my WPF app: for a button with a context menu, how can I open the menu on hold down of the left mouse (and of course still with the regular right click)?
I would suggest to handle the
MouseDown
event by starting a timer there. If theMouseUp
event is fired, the timer needs to be stopped. You can use aDispatcherTimer
for that. Then you can set up a time after that theTimer_Tick
event should be fired, where you can perform the action you would like to perform. In order to avoid problems with the bubblingMouseDown
andMouseUp
events, I would suggest to add the two handlers in the window constructor instead of adding them in XAML (at least the events did not fire in my example code, so i changed that) by usingAdditionally, you need to set up the timer there:
Add a field to the window class:
and set up the timer with the time you want to wait until the
Timer_Tick
event is fired (also in the window constructor):Then you only need to handle the events and you are done:
Hope that helps.