开发者

MouseDoubleClick & Touch on a ScatterViewItem

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;

    开发者_JAVA百科            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;
        }
    }


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....


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜