How To Get Events About Touch Contact Points In Windows Phone 7

<< Back to the Windows Phone page

There are two major methods to receive information about touch events:

1. Subscribing for gestures and single touch contacts (= mouse click events): To learn more about this programming strategy have a look at the following tutorial:
http://create.msdn.com/en-US/education/quickstarts/Touch_Input

2. Subscribing for low-level events about any multi-touch contact: Using the following lines of code you can receive updates about any touch contacts on the screen of the mobile phone.

a) Register for touch events ; e.g., by putting the following line in your constructor:

Touch.FrameReported += new TouchFrameEventHandler(Touch_FrameReported);

b) Handle touch events in the callback method

void Touch_FrameReported(object sender, TouchFrameEventArgs e)
{
  // Get primary touch point
  TouchPoint point = e.GetPrimaryTouchPoint(this.canvas);

  // ... or get all current touch points on screen
  TouchPointCollection tpc = e.GetTouchPoints(this.canvas);

  // Iterate over all touch points in the collection
  foreach (TouchPoint touchPoint in tpc)
  {
    // Get X and Y position of the touch point
    touchPoint .Position.X;
    touchPoint .Position.Y;

    [...]
  }
}