鼠标双击触摸 ScatterViewItem

发布于 2024-11-27 14:27:33 字数 1499 浏览 3 评论 0原文

我开发了一个 WPF4 触摸应用程序,它使用一些 Microsoft Surface 控件。我想捕获 ScatterViewItem 上的 MouseDoubleClick 事件。当我使用鼠标时该事件会触发,但是当我使用手指时,该事件永远不会引发。为什么 ?

多谢。

更新

我最终编写了这段代码,在有限的矩形(16px 宽度和高度)上重现 TouchLeave 事件的简单双击,并在 2 个 TouchLeave 事件之间所需的时间为 500 毫秒。该代码尚未优化,但它可以工作,如果您有任何意见,请不要犹豫:)

private bool _doubleHasTimeAndPos = false;

private TimeSpan? _doubleTouchTime = null;
private Point? _doubleTouchPoint = null;    

private void ScatterViewItem_TouchLeave(object sender, TouchEventArgs e)
    {
        if (!this._doubleHasTimeAndPos)
        {
            this._doubleTouchTime = DateTime.Now.TimeOfDay;
            this._doubleTouchPoint = e.GetTouchPoint(this.scatterView).Position;

            this._doubleHasTimeAndPos = true;
        }
        else
        {
            if (DateTime.Now.TimeOfDay.Subtract(this._doubleTouchTime.Value).TotalMilliseconds <= 500)
            {
                Point touchPoint = e.GetTouchPoint(this.scatterView).Position;

                double xDelta = Math.Abs(this._doubleTouchPoint.Value.X - touchPoint.X);
                double yDelta = Math.Abs(this._doubleTouchPoint.Value.Y - touchPoint.Y);

                if (xDelta <= 16 && yDelta <= 16)
                {
                    // DOUBLE TAP here !
                }
            }

            this._doubleTouchTime = null;
            this._doubleTouchPoint = null;

            this._doubleHasTimeAndPos = false;
        }
    }

I develop a WPF4 touch aplication which use some Microsoft Surface controls. I would like to catch the MouseDoubleClick event on a ScatterViewItem. The event fires when i use the mouse, but when i use my finger, the event is never raised. Why ?

Thanks a lot.

UPDATE :

I finally wrote this code to reproduce a simple double tap with TouchLeave event on a limited rect (16px width & height) and 500ms for the required time between 2 TouchLeave events. This code is not optimized but it works, if you have some remark, don't hesitate :)

private bool _doubleHasTimeAndPos = false;

private TimeSpan? _doubleTouchTime = null;
private Point? _doubleTouchPoint = null;    

private void ScatterViewItem_TouchLeave(object sender, TouchEventArgs e)
    {
        if (!this._doubleHasTimeAndPos)
        {
            this._doubleTouchTime = DateTime.Now.TimeOfDay;
            this._doubleTouchPoint = e.GetTouchPoint(this.scatterView).Position;

            this._doubleHasTimeAndPos = true;
        }
        else
        {
            if (DateTime.Now.TimeOfDay.Subtract(this._doubleTouchTime.Value).TotalMilliseconds <= 500)
            {
                Point touchPoint = e.GetTouchPoint(this.scatterView).Position;

                double xDelta = Math.Abs(this._doubleTouchPoint.Value.X - touchPoint.X);
                double yDelta = Math.Abs(this._doubleTouchPoint.Value.Y - touchPoint.Y);

                if (xDelta <= 16 && yDelta <= 16)
                {
                    // DOUBLE TAP here !
                }
            }

            this._doubleTouchTime = null;
            this._doubleTouchPoint = null;

            this._doubleHasTimeAndPos = false;
        }
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

谁把谁当真 2024-12-04 14:27:33

由于缺乏触摸基础设施来测试此代码,这只是猜测...

WPF 建议对任何 UIElement 使用 Mouse.MouseDown 附加事件,然后使用 ((MouseButtonEventArgs)e.ClickCount) 检查双击的值 2。

     <ScatterViewItem Mouse.MouseDown="MouseButtonEventHandler" ... />

然后

     private void MouseButtonDownHandler(object sender, MouseButtonEventArgs e)
     {
           if (e.ClickCount == 2) 
           {
                  //// Its a double click... should work for touch.
           }
     }

让我知道这是否有效......

Just a guess due to lack of touch infrastructure to test this code ...

WPF recommends using Mouse.MouseDown attached event for any UIElement and then using ((MouseButtonEventArgs)e.ClickCount) to be checked for value 2 for double click.

     <ScatterViewItem Mouse.MouseDown="MouseButtonEventHandler" ... />

And then

     private void MouseButtonDownHandler(object sender, MouseButtonEventArgs e)
     {
           if (e.ClickCount == 2) 
           {
                  //// Its a double click... should work for touch.
           }
     }

Let me know if this works....

多像笑话 2024-12-04 14:27:33

在 API 级别,触摸事件不会生成双击事件。

此外,微软的 Surface UI 设计指南(免责声明:我帮助编写了它们)实际上强烈建议不要使用“双击”的概念。触摸旨在为用户提供一种更“自然”的与技术交互的方式,而不需要任何培训、文档或记忆“隐藏”功能。双击不是人类在物理世界中进行的交互,也不是任何视觉可供性的东西。因此,不适合在软件应用中使用。苹果同意这一理念,顺便说一句 - 你不会在 iPhone 或 iPad 上看到任何双击交互。

At an API level, touch events will not generate double click events.

Furthermore, Microsoft's Surface UI design guidelines (disclaimer: I helped write them) actually advise strongly against the concept of "double tap". Touch is meant to give user a more 'natural' way of interacting with technology without the need for any traning, documentation, or memorization of 'hidden' features. Double-tap is not an interaction humans do in the physical world and is not something that there are any visual affordances for. Therefore, it is not appropriate to use in software applications. Apple concurs with this philosophy, btw - you won't see any double-tap interactions on the iPhone or iPad.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文