Disable a right click (press and hold) in WPF application.

Vitalij picture Vitalij · May 11, 2011 · Viewed 13.4k times · Source

I am working on the touch screen application which is running on Windows XP Standard. With current hardware to invoke a right click user has to click and hold for couple of seconds, but this might interfere with other actions like holding a repeat button in the scrollviewer, so I have decide to disable a right click.

I would ideally wan't to disable a right click on the application level, but if it is not possible, disable right click on windows level would also work for me.

Answer

Mike Fuchs picture Mike Fuchs · Aug 2, 2011

The OnPreviewMouseRightButtonDown/Up approach did not work for me.

  1. There is a property Stylus.IsPressAndHoldEnabled on UIElement however. Set that to false to get rid of the press and hold right click behavior. I tested this on Windows 7 with .NET 4.0, but the property is available from .NET 3.0.

    <RepeatButton Stylus.IsPressAndHoldEnabled="false" ... />

  2. There is also a blogpost here that provides a code sample for a similar disabling of press and hold at window level. But with this in place, the PreviewTouchDown and TouchDown events will not be raised as soon as the finger touches the screen (which would be necessary for a RepeatButton I guess), only later. Read the 'Remarks' on this msdn page.