右键双击和上下文菜单
相关问题(详细信息)
我有一个与 ContextMenu 关联的 WPF 画布..
这很酷。现在我必须对 Right DoubleClick 执行一些操作...
事实上,我从未收到 Right mouse ClickCount == 2...
该怎么办?
我需要在简单(右键)单击时显示 ContextMenu,并执行 Action2 OnRightDoubleClick..
protected override void OnPreviewMouseRightButtonUp(MouseButtonEventArgs e)
{
if (e.ClickCount == 1)
{
#region SINGLE CLICK
stillSingleClick = true;
Thread thread = new Thread(
new System.Threading.ThreadStart(
delegate()
{
Thread.Sleep(System.Windows.Forms.SystemInformation.DoubleClickTime);
this.Dispatcher.Invoke(
System.Windows.Threading.DispatcherPriority.Background,
new Action(
delegate()
{
if (stillSingleClick)
{
base.OnPreviewMouseRightButtonUp(e);
}
stillSingleClick = false;
}
));
}
));
thread.Start();
#endregion SINGLE CLICK
}
else if (e.ClickCount == 2)
{
stillSingleClick = false;
base.OnPreviewMouseRightButtonUp(e);
}
}
Related Question (Details)
Tunneling events and ContextMenu
I have a WPF canvas to which I associated a ContextMenu..
This is cool. Now I have to implement some action on Right DoubleClick...
In fact, I never receive on Right mouse ClickCount == 2...
What to do?
I need to display ContextMenu on simple (right) click, and perform Action2 OnRightDoubleClick..
protected override void OnPreviewMouseRightButtonUp(MouseButtonEventArgs e)
{
if (e.ClickCount == 1)
{
#region SINGLE CLICK
stillSingleClick = true;
Thread thread = new Thread(
new System.Threading.ThreadStart(
delegate()
{
Thread.Sleep(System.Windows.Forms.SystemInformation.DoubleClickTime);
this.Dispatcher.Invoke(
System.Windows.Threading.DispatcherPriority.Background,
new Action(
delegate()
{
if (stillSingleClick)
{
base.OnPreviewMouseRightButtonUp(e);
}
stillSingleClick = false;
}
));
}
));
thread.Start();
#endregion SINGLE CLICK
}
else if (e.ClickCount == 2)
{
stillSingleClick = false;
base.OnPreviewMouseRightButtonUp(e);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
MouseButtonEventArgs.ClickCount
将始终为 1,因为您处理的是向上事件而不是向下事件。 PreviewUp 和 Up 都始终为 1。单击行为通常定义为相应按钮的按下事件。MouseButtonEventArgs.ClickCount
will always be 1 since you are handling an up event not a down event. Both the PreviewUp and Up will always be 1. The click behavior is usually defined as the down event of the respective button.在
MouseDoubleClickEvent
中执行此操作Do this in
MouseDoubleClickEvent
在 MSDN 上查看此示例:
Check out this example at MSDN: