1

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;
        }
    }
Nico
  • 575
  • 3
  • 8
  • 19
  • 1) you shouldnt do this - see my answer below. 2) you should use TouchUp instead of TouchLeave. Leave is raised under several circumstances other than actually lifting your finger. 3) to compare coordinates between touch events, you need to use coordinates relative to the screen rather than the scatterview. the scatterview or even the window it's in could itself move between events. this is a common source of difficult to diagnose bugs – Robert Levy Aug 02 '11 at 20:59
  • thanks for your remark, but the TouchDown/TouchUp event seems to never be raised on my ScatterViewItem... I don't know why... – Nico Aug 03 '11 at 07:40

2 Answers2

0

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

WPF-it
  • 19,625
  • 8
  • 55
  • 71
  • Doesn't work, the event is never raised... :( in fact, I think there aren't any mouse event which work with touch on a ScatterViewItem... I tried this : Mouse.AddMouseDownHandler(myScatterItem, new MouseButtonEventHandler(TestMouseDown)); myScatterItem.MouseDown += blablabla... – Nico Aug 02 '11 at 13:47
  • My Bad! This is clearly a Touch related event and wont work similar to mouse double click. Only way to assume a double tap is to handle a TouchDown event and have an attached behavior that will keep the difference between two subsequent touch downs on same element (to which the behavior is attached) in proximity such as half a second difference.... – WPF-it Aug 02 '11 at 14:06
0

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.

Robert Levy
  • 28,747
  • 6
  • 62
  • 94
  • I am with you regarding the double taps as not the primary selection action for touch screens, but having said that iPhones \ iPads do support Double Taps for Zooming. So it can be an option for user action. – WPF-it Aug 03 '11 at 07:55