TouchFrameEventArgs.GetPrimaryTouchPoint(IInputElement) 메서드

정의

지정된 요소를 기준으로 기본 터치 디바이스의 현재 터치 지점을 반환합니다.

public:
 System::Windows::Input::TouchPoint ^ GetPrimaryTouchPoint(System::Windows::IInputElement ^ relativeTo);
public System.Windows.Input.TouchPoint GetPrimaryTouchPoint (System.Windows.IInputElement relativeTo);
member this.GetPrimaryTouchPoint : System.Windows.IInputElement -> System.Windows.Input.TouchPoint
Public Function GetPrimaryTouchPoint (relativeTo As IInputElement) As TouchPoint

매개 변수

relativeTo
IInputElement

좌표 공간을 정의하는 요소입니다. WPF 절대 좌표를 사용하려면 relativeTonull로 지정합니다.

반환

지정된 요소를 기준으로 기본 TouchDevice의 현재 위치이거나, 기본 TouchDevice가 활성화되지 않은 경우 null입니다.

예제

다음 코드에서 검색 된 터치 포인트를 처리 합니다 TouchFrameEventArgs합니다. 터치를 눌렀음을 합니다 Canvas, TouchDevice 에 캡처되는지를 Canvas입니다. 터치 리프트 된 때를 TouchDevice 해제 됩니다. 터치에서 이동 하는 경우는 Canvas, Id 확인란이 선택 되어 있습니다. 경우는 Id 일치 하는 Id 첫 번째 터치를 나타내는 기본 터치 지점의 위치 기록 됩니다. 두 번째 터치에서 이동 하는 경우, 두 번째 터치 위치를 줄의 첫 번째 터치 위치에서 그려집니다.

이 예제는에서 사용할 수 있는 보다 큰 예제의 일부는 Touch 클래스 개요입니다.

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

    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;
            this.canvas1.Children.Add(_line);
        }
    }

    else if (_touchPoint.Action == TouchAction.Up)
    {
        // If this touch is captured to the canvas, release it.
        if (_touchPoint.TouchDevice.Captured == this.canvas1)
        {
            this.canvas1.ReleaseTouchCapture(_touchPoint.TouchDevice);
        }
    }
}
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

설명

활성 집합에서 첫 번째 디바이스를 디바이스를 터치 Activated 주 터치 디바이스가 있습니다. 예를 들어, 두 손가락으로 화면을 터치 하는 경우 아래에 있는 첫 번째 손가락 주 터치 디바이스에 의해 표시 됩니다. 두 번째 손가락은 계속 하는 동안 첫 번째 손가락 리프트 된 기본 터치 디바이스 됩니다 null합니다.

적용 대상