TouchFrameEventArgs.GetPrimaryTouchPoint(IInputElement) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
지정된 요소를 기준으로 기본 터치 디바이스의 현재 터치 지점을 반환합니다.
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 의 현재 위치이거나 null 주 TouchDevice 요소가 활성 상태가 아닌 경우입니다.
예제
다음 코드는 에서 TouchFrameEventArgs검색되는 터치 포인트를 처리합니다. 터치를 누르면 CanvasTouchDevice 에 캡처됩니다Canvas. 터치가 해제되면 TouchDevice 해제됩니다. 터치가 가로 CanvasId 로 이동하면 확인됩니다. 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.