Id Property
Collapse the table of content
Expand the table of content

TouchDevice.Id Property

Gets the unique identifier of the TouchDevice, as provided by the operating system.

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

public int Id { get; }

Property Value

Type: System.Int32
The unique identifier of the TouchDevice.

A TouchDevice represents a single touch on a screen. If multiple touches are present, use the Id property to distinguish between them.

The following example handles the TouchMove events that occur on a Canvas. When a touch moves on the Canvas, the Id is checked. If the move came from 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 available in the TouchDevice class overview.

private void canvas_TouchMove(object sender, TouchEventArgs e)
    Canvas _canvas = (Canvas)sender as Canvas;
    if (_canvas != null)
        TouchPoint tp = e.GetTouchPoint(_canvas);
        // This is the first touch point; just record its position.
        if (e.TouchDevice.Id == firstTouchId)
            pt1.X = tp.Position.X;
            pt1.Y = tp.Position.Y;
        // This is not the first touch point; draw a line from the first point to this one.
        else if (e.TouchDevice.Id != firstTouchId)
            pt2.X = tp.Position.X;
            pt2.Y = tp.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;

.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.

Community Additions

© 2016 Microsoft