0

相关问题(详情)

隧道事件和 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);
    }
}
4

3 回答 3

1

MouseButtonEventArgs.ClickCount将始终为 1,因为您正在处理向上事件而不是向下事件。PreviewUp 和 Up 都将始终为 1。单击行为通常定义为相应按钮的向下事件。

于 2010-12-16T16:44:03.060 回答
0

这样做MouseDoubleClickEvent

if (e.ChangedButton == MouseButton.Right)
{
     //do something with Mouse Right Double Click
}
于 2010-12-16T17:59:49.420 回答
-1

在 MSDN 上查看此示例:

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";
    }
}
于 2010-12-16T16:43:54.683 回答