This documentation is archived and is not being maintained.

TouchFrameEventArgs.GetPrimaryTouchPoint Method

Returns the current touch point of the primary touch device relative to the specified element.

Namespace:  System.Windows.Input
Assembly:  PresentationCore (in PresentationCore.dll)

public TouchPoint GetPrimaryTouchPoint(
	IInputElement relativeTo


Type: System.Windows.IInputElement
The element that defines the coordinate space. To use WPF absolute coordinates, specify relativeTo as null.

Return Value

Type: System.Windows.Input.TouchPoint
The current position of the primary TouchDevice relative to the specified element; or null if the primary TouchDevice is not active.

In a set of active touch devices, the first device to be Activated is the primary touch device. For example, if two fingers are touching the screen, the first finger that is down is represented by the primary touch device. If the first finger is lifted while the second finger is still down, the primary touch device becomes null.

The following code processes the touch points that are retrieved from the TouchFrameEventArgs. When a touch is pressed on the Canvas, the TouchDevice is captured to the Canvas. When the touch is lifted, 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.

foreach (TouchPoint _touchPoint in e.GetTouchPoints(this.canvas1))
    if (_touchPoint.Action == TouchAction.Down)
        // Clear the canvas and capture the touch to it.

    else if (_touchPoint.Action == TouchAction.Move && e.GetPrimaryTouchPoint(this.canvas1) != null)
        // This is the first (primary) touch point. Just record its position.
        if (_touchPoint.TouchDevice.Id == e.GetPrimaryTouchPoint(this.canvas1).TouchDevice.Id)
            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.
        else if (_touchPoint.TouchDevice.Id != e.GetPrimaryTouchPoint(this.canvas1).TouchDevice.Id)
            pt2.X = _touchPoint.Position.X;
            pt2.Y = _touchPoint.Position.Y;

            Line _line = 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;

    else if (_touchPoint.Action == TouchAction.Up)
        // If this touch is captured to the canvas, release it.
        if (_touchPoint.TouchDevice.Captured == this.canvas1)

.NET Framework

Supported in: 4

.NET Framework Client Profile

Supported in: 4

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.