Reputation: 271
I used this code in windows phone 8:
public partial class MainPage : PhoneApplicationPage
{
// Constructor
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);//Displaying x&y co-ordinates of Touch point
}
}
but is not working in windows 10 universal app.
Upvotes: 0
Views: 2151
Reputation: 120
I think you can get the result by using this code:
private void _theCanvas_Tapped(object sender, TappedRoutedEventArgs e)
{
_pointerDeviceType.Text = e.PointerDeviceType.ToString();
var position = e.GetPosition(_root);
_x.Text = position.X.ToString();
_y.Text = position.Y.ToString();
}
The e.GetPosition()-Method helps you to get the position based on another control. The full sample code including the XAML is here: https://github.com/TheOliver/Windows-10-Feature-Demos/blob/master/Windows10FeatureDemos/Windows10FeatureDemos/Samples/HowToGetCoordinatesOfTouchPoints.xaml.cs & and here https://github.com/TheOliver/Windows-10-Feature-Demos/blob/master/Windows10FeatureDemos/Windows10FeatureDemos/Samples/HowToGetCoordinatesOfTouchPoints.xaml
I hope this helps. Oliver
Upvotes: 1