忽略WPF中的单击 [英] Ignore Single Click in WPF

查看:172
本文介绍了忽略WPF中的单击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用户控件,其中我想做一些不同的情况下单击或双击。我正在处理mouseLeftButtonDown事件:

I have a user control wherein I would like to do something different in the case of a single click vs. double click. I'm handling mouseLeftButtonDown event as such:

 private void cueCanvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        switch (e.ClickCount)
        {
            case 1:
                {
                    cueCanvas.Focus();
                    e.Handled = true;
                    _mouseStartPoint = Mouse.GetPosition(null);
                    break;
                }
            case 2:
                {
                    double pos = Mouse.GetPosition(cueCanvas).X;
                    TimeSpan time = ConvertFromPosition(pos);
                    AddNewEvent(time);
                    e.Handled = true;
                    break;
                }
        }
    }

问题是WPF doesn真的关心你点击鼠标的次数,所以我得到第一次点击事件,即使我要获得第二个(在双击的情况下)。有没有人想出一个办法解决这个问题?我意识到我可以尝试获得聪明,并设置一些计时器,使得第一次点击获得取消在第二个进来的事件(我意识到这是框架将做什么)。如果这是唯一的答案,有没有人知道我们如何查询系统适当的点击延迟?

The problem is that WPF doesn't really care how many times you've clicked the mouse so I get the first click event even though I'm about to get a second one (in the case of a double-click). Has anyone come up with a way to work around this? I realize I could try to get clever and set some timers such that the first click gets "canceled" in the event that the second one comes in (I realize this is what the framework would be doing anyway). If that's the only answer, does anyone know how we query the system for the appropriate click delay?

推荐答案

据我所知,真的没办法做到这一点。问题是你在战斗现实。 :-)在现实中,有两次点击双击。如果快速按下双击,您想要忽略单击。

To my knowledge, there's really no way to do this. The problem is that you're fighting reality. :-) In reality, there are 2 clicks to a double-click. You want single click to be ignored if quickly followed by a double-click.

您将等待一段时间,看看是否有第二次点击。您可以使用系统信息查询该时间间隔WinForms类别,或直接调用 Win32 API

You'll have wait a short interval to see if it's followed by a second click. You can query for that interval using the SystemInformation class from WinForms, or just call the Win32 API directly.

这篇关于忽略WPF中的单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆