Returns a collection that contains the current touch point for each active touch device relative to the specified element.
Assembly: PresentationCore (in PresentationCore.dll)
'Declaration Public Function GetTouchPoints ( _ relativeTo As IInputElement _ ) As TouchPointCollection
- Type: System.Windows.IInputElement
The element that defines the coordinate space. To use WPF absolute coordinates, specify relativeTo as Nothing.
The following code processes the touch points retrieved from the TouchFrameEventArgs. When a touch is pressed on the canvas, the TouchDevice is captured to the canvas. When the touch is raised, the TouchDevice is released. When a touch moves across the canvas, the Id is checked. If the Id matches the Id of the primary touch point, which indicates the first touch, its location is recorded. If the move came from the second touch, a line is drawn from the position of the first touch to the position of the second touch.
This example is part of a larger example that is available in the Touch class overview.
For Each _touchPoint In e.GetTouchPoints(Me.canvas1) If _touchPoint.Action = TouchAction.Down Then ' Clear the canvas and capture the touch to it. canvas1.Children.Clear() _touchPoint.TouchDevice.Capture(canvas1) ElseIf _touchPoint.Action = TouchAction.Move Then ' This is the first (primary) touch point. Just record its position. If _touchPoint.TouchDevice.Id = e.GetPrimaryTouchPoint(Me.canvas1).TouchDevice.Id Then pt1.X = _touchPoint.Position.X pt1.Y = _touchPoint.Position.Y ' This is not the first touch point; draw a line from the first point to this one. ElseIf _touchPoint.TouchDevice.Id <> e.GetPrimaryTouchPoint(Me.canvas1).TouchDevice.Id Then pt2.X = _touchPoint.Position.X pt2.Y = _touchPoint.Position.Y Dim _line As New Line() _line.Stroke = New RadialGradientBrush(Colors.White, Colors.Black) _line.X1 = pt1.X _line.X2 = pt2.X _line.Y1 = pt1.Y _line.Y2 = pt2.Y _line.StrokeThickness = 2 Me.canvas1.Children.Add(_line) End If ElseIf _touchPoint.Action = TouchAction.Up Then ' If this touch is captured to the canvas, release it. If (_touchPoint.TouchDevice.Captured Is canvas1) Then canvas1.ReleaseTouchCapture(_touchPoint.TouchDevice) End If End If Next