Detecting and handling multi-touch events in Windows Phone 7 applications
This article provides a simple code snippet showing how to capture multi-touch events on Windows Phone 7 using touch framereported .This event will active for touch activity across the entire application.The Touch framework has two primary concepts: the TouchPoint object and the FrameReported event.The TouchPoint object stores data related to a single touch point. The first touch point that is fired to the application is called the primary touch point. The object has two important properties: Position and Action. The Action property stores the current action state, such as Up, Down, and Move. The Up and Down actions are similar to the mouse's MouseLeftButtonUp and MouseLeftButonDown events. The Move action is the transition action that is constantly called until the user releases the Touch Point, which also invokes the Up action. The TouchFrameEventArgs argument has methods of getting information about touch points. You can get the current touch points by calling the GetPrimaryTouchPoint and GetTouchPoint methods.GetPrimaryTouchPoint is called to get single-touch data,If multiple fingers are pressed on the screen, GetPrimaryTouchPoint returns data about the first finger that makes contact with the screen.
Basic Implementation code
public partial class MainPage : PhoneApplicationPage
protected override void OnNavigatedTo(NavigationEventArgs e)
Touch.FrameReported += Touch_FrameReported;//touch/multi-touch event.
void Touch_FrameReported(object sender, TouchFrameEventArgs e)
TouchPointCollection points = e.GetTouchPoints(this);
int numPoints =(from p in points where p.Action != TouchAction.Up select p).Count();
LINQ query to set the value of numPoints.Here I filter out the touch points whose Action proprty is "UP" because the counting of touch points does not tell us howmany fingers are currently in contact with the screen.
As the touch event get raised for touch activity across the entire application you must unsubscribe FrameReported handlers being invoked when they don’t need,forgetting to detach from this event can cause other problems.Windows Phone guaranteed to support four simultaneous touch points.