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

Published on December 26, 2013 by abundantcode

Filed under Windows Phone

Last modified December 26, 2013

Print this page

rate 1 star rate 2 star rate 3 star rate 4 star rate 5 star
Your rating: none, Average: 0 (0 votes)

This article have been viewed 3500 times

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 ?

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

Leave a Comment


x

You might be Interested in these Posts

How to delete user account from command line in Windows 10 ?

You can delete a user account from command line in Windows 10 using the net user command and specify...

How to add new user account from command line in Windows 10 ?

You can add a new user account in Windows 10 using command prompt using the net user command and pas...

How to open display settings from command line in Windows 10 ?

The display properties can be found in the settings app in Windows 10 which lets the users to config...