Namespaces
Variants
Actions

Detecting and handling multi-touch events in Windows Phone 7 applications

Jump to: navigation, search

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.

WP Metro Icon UI.png
Article Metadata

Tested with
SDK: Windows Phone SDK 7.1
Devices(s): Nokia Lumia 800

Compatibility
Platform(s): Windows Phone 7.5 (Mango)

Article
Created: sreerajvr (06 Apr 2012)
Last edited: hamishwillee (30 Nov 2012)

Basic Implementation code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Windows.Navigation;
 
namespace Multtouch
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(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.
 
*/

MessageBox.Show(numPoints.ToString());
}
}
}

Summary

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.

This page was last modified on 30 November 2012, at 08:15.
242 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved