How to Find if the User has tapped on the Screen in Windows Phone 8 App ?

There are times when you want to find out if the user has tapped on the screen to perform some action .

For example , you are developing a game and want the user to tap anywhere on the screen to proceed . In these scenario , one can use the Touch.FrameReported event which lets you capture the position on the screen where the user has tapped.

How to Find if the User has tapped on the Screen in Windows Phone 8 App ?

The Touch.FrameReported event is defined in the namespace “System.Windows.Input” and the event occurs when a touch message is sent from the UI.

Below is a sample code snippet demonstrating how to get the position where the user clicked on the screen using Touch.FrameReported event.

using Microsoft.Phone.Controls;
using System;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Windows.System;

namespace AbundantCodeWP8
{
    public partial class MainPage : PhoneApplicationPage
    {
        public MainPage()
        {
            InitializeComponent();
            Touch.FrameReported += Touch_FrameReported;
        }

        void Touch_FrameReported(object sender, TouchFrameEventArgs e)
        {
            TouchPoint touchPoint = e.GetTouchPoints(this.ContentPanel).FirstOrDefault();
            if (touchPoint.Action == TouchAction.Up)
                MessageBox.Show(touchPoint.Position.X + "," + touchPoint.Position.Y);
        }
}
How to Find if the User has tapped on the Screen in Windows Phone 8 App ?
%d