Tunneling events and ContextMenu
我有一个WPF画布,我将它关联到ContextMenu ..
这很酷。现在我必须在Right DoubleClick上实施一些操作......
事实上,我从未收到过鼠标右键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);
}
}
答案 0 :(得分:1)
MouseButtonEventArgs.ClickCount
将始终为1,因为您正在处理up事件而不是down事件。 PreviewUp和Up都将始终为1.点击行为通常被定义为相应按钮的向下事件。
答案 1 :(得分:0)
在MouseDoubleClickEvent
if (e.ChangedButton == MouseButton.Right)
{
//do something with Mouse Right Double Click
}
答案 2 :(得分:-1)
在MSDN上查看this示例:
private void OnMouseDownClickCount(object sender, MouseButtonEventArgs e)
{
//Handle only right clicks
if (e.RightButton != MouseButtonState.Pressed) return;
// Checks the number of clicks.
if (e.ClickCount == 1)
{
// Single Click occurred.
lblClickCount.Content = "Single Click";
}
if (e.ClickCount == 2)
{
// Double Click occurred.
lblClickCount.Content = "Double Click";
}
if (e.ClickCount >= 3)
{
// Triple Click occurred.
lblClickCount.Content = "Triple Click";
}
}