private void canvas_TouchDown(object sender, TouchEventArgs e) { TouchPoint touchPoint = e.GetTouchPoint(canvas); double x = touchPoint.Position.X; double y = touchPoint.Position.Y; // do something with the coordinates }
private void listBox_TouchMove(object sender, TouchEventArgs e) { ListBoxItem listBoxItem = FindVisualParentIn this example, the TouchMove event on a ListBox element is handled. The code first finds the ListBoxItem that the touch event occurred on by calling a helper method. Then, the GetTouchPoint method is called on the event arguments object to retrieve the touch point coordinates relative to the ListBoxItem element. The package library for the System.Windows.Input namespace is PresentationCore.dll.(e.OriginalSource as DependencyObject); if (listBoxItem != null) { TouchPoint touchPoint = e.GetTouchPoint(listBoxItem); double x = touchPoint.Position.X; double y = touchPoint.Position.Y; // do something with the coordinates } } private static T FindVisualParent (DependencyObject child) where T : DependencyObject { while (child != null) { DependencyObject parent = VisualTreeHelper.GetParent(child); T parentAsT = parent as T; if (parentAsT != null) { return parentAsT; } child = parent; } return null; }