Strategy for differentiating TouchUp from TouchLeave, and TouchDown from TouchEnter?
Asked Answered
M

2

6

For the basic scenario described in the msdn overview (under Touch and Manipulation) TouchEnter and TouchLeave are fired for every corresponding TouchDown and TouchUp respectively. Unlike the mouse, the Touch and Stylus are not constrained to maintain contact with the screen.

Is there a way to use TouchEnter and TouchLeave is to capture only when a finger is dragged into the UIElement. As these events are fired for every touchUp and touchDown, what is the best way to differentiate these events?

One strategy that would work for the single finger case, is to have a flag set on TouchDown, and check if the flag is set on TouchUp. This allows some condition checks on TouchUp. However, for multiple fingers, it isn't feasible.

There are no PreviewTouchEnter and PreviewTouchLeave events fired, only PreviewTouchDown and PreviewTouchUp. The sequence of events for a finger lowered on to a UIElement and then raised over it is as follows:

  1. TouchEnter
  2. PreviewTouchDown
  3. TouchDown
  4. PreviewTouchUp
  5. TouchUp
  6. TouchLeave

This sequence doesn't help differentiate a TouchEnter that has happened due to a finger dragged across the screen into the UIElement, from a finger that is lowered onto the UIElement directly. Am I missing something, or does the framework not support such differentiation itself?

Malapropism answered 15/1, 2012 at 22:53 Comment(0)
T
0

Can you use the TouchDevice Class to keep track of where touches are generated. New touches are given a new ID, so you could distinguish between existing touches and new ones, and which elements are capturing the device. I guess that circumvents the Manipulation events and the normal processes, but I hope that helps.

Twomey answered 17/4, 2013 at 14:54 Comment(0)
C
0

If you retrieve a TouchPoint for the event, there is a property on it named Action which tells you whether it is a Down, a Move or a Up event.

void m_element_TouchEnter(object sender, System.Windows.Input.TouchEventArgs e)
{
    var touchPoint = e.GetTouchPoint(m_someElement);

    if (touchPoint.Action == System.Windows.Input.TouchAction.Move)
    {
        //This is a "true" TouchEnter event
    }
    else if (touchPoint.Action == System.Windows.Input.TouchAction.Down)
    {
        //This is a "true" TouchDown event.
    }
}
Chitin answered 25/4, 2014 at 15:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.