在 WPF 应用程序中禁用右键单击(按住)。
我正在开发在 Windows XP Standard 上运行的触摸屏应用程序。使用当前的硬件来调用右键单击,用户必须单击并按住几秒钟,但这可能会干扰其他操作,例如在滚动查看器中按住重复按钮,因此我决定禁用右键单击。
理想情况下,我不想禁用应用程序级别的右键单击,但如果不可能,禁用窗口级别的右键单击也适合我。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
OnPreviewMouseRightButtonDown/Up 方法对我不起作用。
UIElement 上有一个属性 Stylus.IsPressAndHoldEnabled然而。将其设置为 false 以消除按住右键单击行为。我在带有 .NET 4.0 的 Windows 7 上对此进行了测试,但该属性可从 .NET 3.0 获得。
还有一篇博文此处提供了在窗口级别类似地禁用按住的代码示例。但有了这个,一旦手指触摸屏幕,PreviewTouchDown 和 TouchDown 事件就不会被引发(我猜这对于 RepeatButton 来说是必要的),只有稍后才会引发。请阅读此 msdn 页面上的“备注”。
The OnPreviewMouseRightButtonDown/Up approach did not work for me.
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" ... />
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.
您可以覆盖窗口上的 OnPreviewMouseRightButtonDown 并将 Handled 设置为 true。您还需要处理 OnPreviewMouseRightButtonUp (感谢 Vitalij 指出这一点)
这应该可以解决问题。
You can override the OnPreviewMouseRightButtonDown on the Window and set Handled to true. You also need to handle OnPreviewMouseRightButtonUp (thanks to Vitalij for pointing this out)
That should do the trick.