相關問題(詳細信息)
Tunneling events and ContextMenuRightDoubleClick和上下文菜單
我有一個WPF畫布我相關的文本菜單..
這是很酷的。現在,我要實現右鍵的DoubleClick一些行動......
事實上,我從來沒有收到鼠標右鍵ClickCount的== 2 ...
怎麼辦?
我需要簡單(右)單擊顯示文本菜單,並執行措施2 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);
}
}
上下文菜單不顯示爲WM_RBUTTONUP的結果爲此,他們將顯示爲WM_CONTEXTMENU的結果。原因是允許鍵盤(Shift + F10或上下文菜單鍵)調用上下文菜單。無法區分從鍵盤或鼠標調用的WM_CONTEXTMENU。如果你想要指定的行爲,你將不得不放棄鍵盤功能。我強烈建議保持「正常」行爲,而不是右鍵雙擊,使用Ctrl +左鍵單擊等其他機制。 – Tergiver 2010-12-16 18:49:01
@Tergiver:謝謝。請參閱http://stackoverflow.com/questions/4464936/tunneling-events-and-contextmenu – serhio 2010-12-16 20:22:07
我沒有仔細閱讀這個問題。我只是假定ClickCount =「1」語句中的代碼是一些動作,但現在我發現它與我提供的答案基本相同。我的不好..已刪除的答案 – 2010-12-16 20:40:55