Strategy for distinguishing TouchUp from TouchLeave and TouchDown from TouchEnter?

For the base scenario described in the msdn overview (in the Touch and Manipulation section), TouchEnter and TouchLeave are launched for each corresponding TouchDown and TouchUp, respectively. Unlike mice, Touch and Stylus are not limited to maintain contact with the screen.

Is it possible to use TouchEnter and TouchLeave to capture only when the finger is dragged into a UIElement. Since these events are fired for each touchUp and touchDown, what is the best way to distinguish these events?

One strategy that will work for the one-finger case is to set the flag on TouchDown and check if the flag is set on TouchUp. This allows some condition checking on TouchUp. However, for a few fingers this is not possible.

There are no PreviewTouchEnter and PreviewTouchLeave events, only PreviewTouchDown and PreviewTouchUp. The sequence of events for a finger dropped onto a UIElement and then raised above it is as follows:

  • Touchenter
  • PreviewTouchDown
  • Touchdown
  • PreviewTouchUp
  • Touchup
  • Touchleave

This sequence does not help to distinguish between TouchEnter, which occurred due to a finger being dragged across the screen in a UIElement, from a finger that directly descends to UIElement. Am I missing something, or does the framework not support this differentiation?

+6
source share
2 answers

Can you use the TouchDevice class to track where touches touch. New strokes get a new identifier, so you can distinguish between existing strokes and new, and which elements capture the device. I suppose that circumvents Manipulation events and normal processes, but I hope this helps.

0
source

If you retrieve a TouchPoint for an event, it has a property named Action that tells you whether the event is Down , Move or Up .

 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. } } 
0
source

Source: https://habr.com/ru/post/906059/


All Articles