Google WindowsPhone :Get X and Y coordinates of user tap/touch relative to screen(C#-XAML) | SubramanyamRaju Xamarin & Windows App Dev Tutorials

Friday, 22 August 2014

WindowsPhone :Get X and Y coordinates of user tap/touch relative to screen(C#-XAML)


This article is explained about "how to get the X Y coordinates of a touch/tap on a touchscreen device powered by WindowsPhone".And we are very lucky,there are tons of guides on how to add a touch handle to a specific screen windows,but I would like to take advantage of "Touch.FrameReported" event is defined in the namespace "System.Windows.Input" and the event occurs when a touch message is sent from the UI.

Note:Manipulation events are the recommended way to handle user input. Unless you have a specific need, you should avoid using mouse events in your Silverlight applications for Windows Phone for performance and hardware compatibility reasons. Instead, you should use manipulation events.

Realtime Example:
Suppose we are trying to develop a handwriting recognition for an application.And we would like to know are there any api or libraries through which we could recognize which alphabet is traced on the screen or which gesture is drawn on the screen other than the prefixed ones like drag, slide, etc....(Example something like InkPresenter is for windowsphone 8)

Touch.FrameReported event is available in windowsphone 7.0 , windowsphone 7.1, windowsphone 8.0.Below is a sample code snippet demonstrating how to get the position where the user clicked on the screen using Touch.FrameReported event.


 public partial class MainPage : PhoneApplicationPage 
        // Constructor 
        public MainPage() 
            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("Selected coordinates:"+touchPoint.Position.X + "," + touchPoint.Position.Y);//Displaying x&y co-ordinates of Touch point 

FeedBack Note:
Please share your thoughts,what you think about this post,Is this post really helpful for you?I always welcome if you drop comments on this post and it would be impressive.

Follow me always at  
Have a nice day by  :)

No comments:

Post a Comment

Search Engine Submission - AddMe