다음을 통해 공유


TouchDevice 클래스

정의

터치 스크린의 손가락으로 생성되는 단일 터치 입력을 나타냅니다.

public ref class TouchDevice abstract : System::Windows::Input::InputDevice, System::Windows::Input::IManipulator
public abstract class TouchDevice : System.Windows.Input.InputDevice, System.Windows.Input.IManipulator
type TouchDevice = class
    inherit InputDevice
    interface IManipulator
Public MustInherit Class TouchDevice
Inherits InputDevice
Implements IManipulator
상속
구현

예제

다음 예제에서는 터치 스크린에서 Canvas 두 손가락을 끌어 간단한 패턴을 만들 수 있습니다. 각 터치는 에 TouchEventArgs있는 a로 TouchDevice 표시됩니다. 패턴은 터치에서 제공하는 터치 포인트 사이에 선을 그려 생성됩니다. 이 예제에서는 Windows 터치 호환 화면이 필요합니다.

다음 태그는 눈금 가운데에 있는 사용자 인터페이스로 구성 Canvas 되고 터치 이벤트에 대한 이벤트 처리기를 연결합니다.

<Window x:Class="WpfTouchEventsSample.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="525" Width="525">
    <Grid>
        <Canvas x:Name="canvas1"
                Width="500" Height="500"
                Background="Black"
                TouchDown="canvas_TouchDown"
                TouchMove="canvas_TouchMove"
                TouchUp="canvas_TouchUp" />
    </Grid>
</Window>

다음 코드는 터치 이벤트를 처리합니다. 터치를 누르면 CanvasTouchDevice 에 캡처됩니다Canvas. 터치가 해제되면 TouchDevice 해제됩니다. 터치가 이동하면 CanvasId 확인됩니다. 첫 번째 터치에서 이동한 경우 해당 위치가 기록됩니다. 두 번째 터치에서 이동하면 첫 번째 터치의 위치에서 두 번째 터치의 위치로 선이 그려집니다.

using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Shapes;
using System.Windows.Controls;

namespace WpfTouchEventsSample
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        // Variables to track the first two touch points 
        // and the ID of the first touch point.
        private Point pt1, pt2 = new Point();
        private int firstTouchId = -1;

        public MainWindow()
        {
            InitializeComponent();
        }

        private void canvas_TouchDown(object sender, TouchEventArgs e)
        {
            Canvas _canvas = (Canvas)sender as Canvas;
            if (_canvas != null)
            {
                _canvas.Children.Clear();
                e.TouchDevice.Capture(_canvas);

                // Record the ID of the first touch point if it hasn't been recorded.
                if (firstTouchId == -1)
                    firstTouchId = e.TouchDevice.Id;
            }
        }

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

        private void canvas_TouchUp(object sender, TouchEventArgs e)
        {
            Canvas _canvas = (Canvas)sender as Canvas;
            if (_canvas != null && e.TouchDevice.Captured == _canvas)
            {
                _canvas.ReleaseTouchCapture(e.TouchDevice);
            }
        }
    }
}
Class MainWindow
    ' Variables to track the first two touch points 
    ' and the ID of the first touch point.
    Private pt1, pt2 As Point
    Private firstTouchId As Integer = -1
    ' Touch Down
    Private Sub canvas_TouchDown(ByVal sender As System.Object, ByVal e As System.Windows.Input.TouchEventArgs)
        Dim _canvas As Canvas = CType(sender, Canvas)
        If (_canvas IsNot Nothing) Then
            _canvas.Children.Clear()
            e.TouchDevice.Capture(_canvas)

            ' Record the ID of the first touch point if it hasn't been recorded.
            If firstTouchId = -1 Then
                firstTouchId = e.TouchDevice.Id
            End If
        End If
    End Sub
    ' Touch Move
    Private Sub canvas_TouchMove(ByVal sender As System.Object, ByVal e As System.Windows.Input.TouchEventArgs)
        Dim _canvas As Canvas = CType(sender, Canvas)
        If (_canvas IsNot Nothing) Then
            Dim tp = e.GetTouchPoint(_canvas)
            ' This is the first touch point; just record its position.
            If e.TouchDevice.Id = firstTouchId Then
                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.
            ElseIf e.TouchDevice.Id <> firstTouchId Then
                pt2.X = tp.Position.X
                pt2.Y = tp.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
                _canvas.Children.Add(_line)
            End If
        End If
    End Sub
    ' Touch Up
    Private Sub canvas_TouchUp(ByVal sender As System.Object, ByVal e As System.Windows.Input.TouchEventArgs)
        Dim _canvas As Canvas = CType(sender, Canvas)
        If (_canvas IsNot Nothing AndAlso e.TouchDevice.Captured Is _canvas) Then
            _canvas.ReleaseTouchCapture(e.TouchDevice)

        End If
    End Sub
End Class

설명

일반적으로 속성을 사용하여 액세스 TouchDevice 합니다 TouchEventArgs.TouchDevice . A TouchDevice 는 화면의 단일 터치를 나타냅니다. 여러 터치가 있는 경우 속성을 사용하여 Id 구분합니다.

메모

이 클래스에는 모든 멤버에 적용되는 클래스 수준의 상속 요청이 포함됩니다. 파생 클래스에 완전 신뢰 권한이 없는 경우 A SecurityException 가 throw됩니다. 보안 요구 사항에 대한 자세한 내용은 링크 요구 사항상속 요구를 참조하세요.

생성자

Name Description
TouchDevice(Int32)

파생 클래스의 생성자에서 호출되어 클래스를 TouchDevice 초기화합니다.

속성

Name Description
ActiveSource

이 디바이스에 PresentationSource 대한 입력을 보고하는 값을 가져옵니다.

Captured

를 캡처한 TouchDevice요소를 가져옵니다.

CaptureMode

의 캡처 정책을 TouchDevice가져옵니다.

DirectlyOver

터치 접점이 직접 끝난 요소를 가져옵니다.

Dispatcher

연결된 이 값을 DispatcherDispatcherObject 가져옵니다.

(다음에서 상속됨 DispatcherObject)
Id

운영 체제에서 제공하는 고유 식별자를 TouchDevice가져옵니다.

IsActive

디바이스가 활성 상태인지 여부를 나타내는 값을 가져옵니다.

Target

에서 입력 TouchDevice을 받는 요소를 가져옵니다.

메서드

Name Description
Activate()

TouchDevice 입력 메시징 시스템에 추가합니다.

Capture(IInputElement, CaptureMode)

지정된 요소를 사용하여 지정된 요소에 대한 터치를 캡처합니다 CaptureMode.

Capture(IInputElement)

캡처 모드를 사용하여 지정된 요소에 대한 터치를 캡처합니다 Element .

CheckAccess()

호출 스레드에 이 DispatcherObject액세스 권한이 있는지 여부를 확인합니다.

(다음에서 상속됨 DispatcherObject)
Deactivate()

입력 메시징 시스템에서 제거합니다 TouchDevice .

Equals(Object)

지정된 개체가 현재 개체와 같은지 여부를 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 사용됩니다.

(다음에서 상속됨 Object)
GetIntermediateTouchPoints(IInputElement)

파생 클래스에서 재정의되는 경우 가장 최근의 터치 이벤트와 이전 터치 이벤트 간에 수집된 모든 터치 포인트를 반환합니다.

GetTouchPoint(IInputElement)

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

GetType()

현재 인스턴스의 Type 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
OnCapture(IInputElement, CaptureMode)

터치가 요소에 캡처될 때 호출됩니다.

OnManipulationEnded(Boolean)

조작이 종료되면 호출합니다.

OnManipulationStarted()

조작이 시작될 때 호출됩니다.

ReportDown()

요소에서 터치가 눌리고 있음을 보고합니다.

ReportMove()

터치가 요소 간에 이동 중임을 보고합니다.

ReportUp()

요소에서 터치가 해제되었음을 보고합니다.

SetActiveSource(PresentationSource)

이 디바이스에 PresentationSource 대한 보고 입력을 설정합니다.

Synchronize()

사용자 인터페이스를 TouchDevice 기본 터치 포인트와 동기화하도록 강제합니다.

ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)
VerifyAccess()

호출 스레드가 이에 DispatcherObject액세스할 수 있도록 합니다.

(다음에서 상속됨 DispatcherObject)

이벤트

Name Description
Activated

TouchDevice 입력 메시징 시스템에 추가되면 발생합니다.

Deactivated

입력 메시징 시스템에서 제거될 때 TouchDevice 발생합니다.

Updated

터치 메시지를 보낼 때 발생합니다.

명시적 인터페이스 구현

Name Description
IManipulator.GetPosition(IInputElement)

개체의 IManipulator 위치를 반환합니다.

IManipulator.Id

운영 체제에서 제공하는 고유 식별자를 TouchDevice 가져옵니다.

IManipulator.ManipulationEnded(Boolean)

조작이 종료되면 발생합니다.

적용 대상