PointerRoutedEventArgs 클래스

정의

마지막 포인터 이벤트 메시지에서 반환된 인수를 포함합니다.

public ref class PointerRoutedEventArgs sealed : RoutedEventArgs
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class PointerRoutedEventArgs final : RoutedEventArgs
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class PointerRoutedEventArgs : RoutedEventArgs
Public NotInheritable Class PointerRoutedEventArgs
Inherits RoutedEventArgs
상속
Object Platform::Object IInspectable RoutedEventArgs PointerRoutedEventArgs
특성

Windows 요구 사항

디바이스 패밀리
Windows 10 (10.0.10240.0에서 도입되었습니다.)
API contract
Windows.Foundation.UniversalApiContract (v1.0에서 도입되었습니다.)

예제

다음 코드 예제에서는 입력 샘플의 시나리오 2를 보여줍니다. 이 코드는 PointerPressed,PointerReleased, PointerEntered, PointerExitedPointerMoved 이벤트를 사용하여 직접 조작하기 위한 몇 가지 사용 패턴을 보여 줍니다.

<StackPanel x:Name="Scenario2Output" ManipulationMode="All">
  <StackPanel Orientation="Horizontal" Margin="0,10,0,0">
    <Button x:Name="scenario2Reset" Content="Reset" 
      Margin="0,0,10,0" Click="Scenario2Reset"/>
  </StackPanel>
  <StackPanel Orientation="Horizontal" >
    <ToggleSwitch x:Name="tbPointerCapture" 
      Header="Pointer Capture" FontSize="20"/>
    <TextBlock x:Name="txtCaptureStatus" 
      Style="{StaticResource BasicTextStyle}"/>
  </StackPanel>
  <Border x:Name="bEnteredExited" Background="Red" 
    Height="300" Width="450" CornerRadius="20" 
    HorizontalAlignment="Left">
    <Grid>
      <TextBlock Style="{StaticResource BasicTextStyle}" Text="" 
        HorizontalAlignment="Center" VerticalAlignment="Center" 
        x:Name="bEnteredExitedTextBlock"/>
      <Ellipse VerticalAlignment="Bottom" Stroke="Silver" 
        StrokeDashArray="2,2" StrokeThickness="2" Margin="2" 
        x:Name="bEnteredExitedTimer" Width="20" Height="20" 
        RenderTransformOrigin="0.5,0.5">
        <Ellipse.RenderTransform >
          <RotateTransform Angle="0" />
        </Ellipse.RenderTransform>
      </Ellipse>
    </Grid>
  </Border>
</StackPanel>
int _pointerCount;

public Scenario2()
{
    this.InitializeComponent();
    bEnteredExited.PointerEntered += bEnteredExited_PointerEntered;
    bEnteredExited.PointerExited += bEnteredExited_PointerExited;
    bEnteredExited.PointerPressed += bEnteredExited_PointerPressed;
    bEnteredExited.PointerReleased += bEnteredExited_PointerReleased;
    bEnteredExited.PointerMoved += bEnteredExited_PointerMoved;

    // To code for multiple Pointers (that is, fingers), 
    // we track how many entered/exited.
    _pointerCount = 0;
}

private void bEnteredExited_PointerMoved(object sender, 
    PointerRoutedEventArgs e)
{
    Scenario2UpdateVisuals(sender as Border, "Moved");
}

private void bEnteredExited_PointerReleased(object sender, 
    PointerRoutedEventArgs e)
{
    ((Border)sender).ReleasePointerCapture(e.Pointer);
    txtCaptureStatus.Text = string.Empty;
}

//Can only get capture on PointerPressed (i.e. touch down, mouse click, pen press)
private void bEnteredExited_PointerPressed(object sender, 
    PointerRoutedEventArgs e)
{
    if (tbPointerCapture.IsOn)
    {
        bool _hasCapture = ((Border)sender).CapturePointer(e.Pointer);
        txtCaptureStatus.Text = "Got Capture: " + _hasCapture;
    }
}

private void bEnteredExited_PointerExited(object sender, 
    PointerRoutedEventArgs e)
{
    _pointerCount--;
    Scenario2UpdateVisuals(sender as Border, "Exited");
}

private void bEnteredExited_PointerEntered(object sender, 
    PointerRoutedEventArgs e)
{
    _pointerCount++;
    Scenario2UpdateVisuals(sender as Border, "Entered");
}

private void Scenario2UpdateVisuals(Border border, 
    String eventDescription)
{
    switch (eventDescription.ToLower())
    {
        case "exited":
            if (_pointerCount <= 0)
            {
                border.Background = new SolidColorBrush(Colors.Red);
                bEnteredExitedTextBlock.Text = eventDescription;
            }
            break;
        case "moved":
            RotateTransform rt = 
                (RotateTransform)bEnteredExitedTimer.RenderTransform;
            rt.Angle += 2;
            if (rt.Angle > 360) rt.Angle -= 360;
            break;
        default:
            border.Background = new SolidColorBrush(Colors.Green);
            bEnteredExitedTextBlock.Text = eventDescription;
            break;
    }
}

private void Scenario2Reset(object sender, RoutedEventArgs e)
{
    Scenario2Reset();
}

private void Scenario2Reset()
{
    bEnteredExited.Background = new SolidColorBrush(Colors.Green);
    bEnteredExitedTextBlock.Text = string.Empty;
}
Private _pointerCount As Integer

Public Sub New()
    Me.InitializeComponent()
    AddHandler bEnteredExited.PointerEntered, AddressOf bEnteredExited_PointerEntered
    AddHandler bEnteredExited.PointerExited, AddressOf bEnteredExited_PointerExited
    AddHandler bEnteredExited.PointerPressed, AddressOf bEnteredExited_PointerPressed
    AddHandler bEnteredExited.PointerReleased, AddressOf bEnteredExited_PointerReleased
    AddHandler bEnteredExited.PointerMoved, AddressOf bEnteredExited_PointerMoved

    'To code for multiple Pointers (i.e. Fingers) we track how many entered/exited.
    _pointerCount = 0
End Sub

''' <summary>
''' Invoked when this page is about to be displayed in a Frame.
''' </summary>
''' <param name="e">Event data that describes how this page was reached.  The Parameter
''' property is typically used to configure the page.</param>
Protected Overrides Sub OnNavigatedTo(e As NavigationEventArgs)
End Sub

Private Sub bEnteredExited_PointerMoved(sender As Object, e As PointerRoutedEventArgs)
    Scenario2UpdateVisuals(TryCast(sender, Border), "Moved")
End Sub

Private Sub bEnteredExited_PointerReleased(sender As Object, e As PointerRoutedEventArgs)
    DirectCast(sender, Border).ReleasePointerCapture(e.Pointer)
    txtCaptureStatus.Text = String.Empty
End Sub

'Can only get capture on PointerPressed (i.e. touch down, mouse click, pen press)
Private Sub bEnteredExited_PointerPressed(sender As Object, e As PointerRoutedEventArgs)
    If tbPointerCapture.IsOn Then
        Dim _hasCapture As Boolean = DirectCast(sender, Border).CapturePointer(e.Pointer)
        txtCaptureStatus.Text = "Got Capture: " & _hasCapture
    End If
End Sub

Private Sub bEnteredExited_PointerExited(sender As Object, e As PointerRoutedEventArgs)
    _pointerCount -= 1
    Scenario2UpdateVisuals(TryCast(sender, Border), "Exited")
End Sub

Private Sub bEnteredExited_PointerEntered(sender As Object, e As PointerRoutedEventArgs)
    _pointerCount += 1
    Scenario2UpdateVisuals(TryCast(sender, Border), "Entered")

End Sub

Private Sub Scenario2UpdateVisuals(border As Border, eventDescription As String)
    Select Case eventDescription.ToLower()
        Case "exited"
            If _pointerCount <= 0 Then
                border.Background = New SolidColorBrush(Colors.Red)
                bEnteredExitedTextBlock.Text = eventDescription
            End If
            Exit Select
        Case "moved"

            Dim rt As RotateTransform = DirectCast(bEnteredExitedTimer.RenderTransform, RotateTransform)
            rt.Angle += 2
            If rt.Angle > 360 Then
                rt.Angle -= 360
            End If
            Exit Select
        Case Else
            border.Background = New SolidColorBrush(Colors.Green)
            bEnteredExitedTextBlock.Text = eventDescription
            Exit Select

    End Select
End Sub

Private Sub Scenario2ResetMethod(sender As Object, e As RoutedEventArgs)
    Reset()
End Sub

Private Sub Reset()
    bEnteredExited.Background = New SolidColorBrush(Colors.Green)
    bEnteredExitedTextBlock.Text = String.Empty
End Sub

설명

대부분의 경우 선택한 언어 프레임워크에서 포인터 이벤트 처리기의 이벤트 인수를 통해 포인터 정보를 가져오는 것이 좋습니다(JavaScript를 사용하는 Windows 앱, C++, C#또는 Visual Basic을 사용하는 UWP 앱 또는 C++와 함께 DirectX를 사용하는 UWP 앱).

이벤트 인수가 앱에 필요한 포인터 세부 정보를 기본적으로 노출하지 않는 경우 PointerRoutedEventArgs의 GetCurrentPointGetIntermediatePoints 메서드를 통해 확장 포인터 데이터에 액세스할 수 있습니다. 이러한 메서드를 사용하여 포인터 데이터의 컨텍스트를 지정합니다.

정적 PointerPoint 메서드인 GetCurrentPointGetIntermediatePoints는 항상 앱의 컨텍스트를 사용합니다. PointerRoutedEventArgs 이벤트 데이터 클래스는 다음 이벤트에 사용됩니다.

중요

마우스 입력이 먼저 감지되면 마우스 입력이 할당된 단일 포인터와 연결됩니다. 마우스 단추(왼쪽, 휠 또는 오른쪽)를 클릭하면 PointerPressed 이벤트를 통해 포인터와 해당 단추 간의 보조 연결이 만들어집니다. PointerReleased 이벤트는 해당하는 동일한 마우스 단추를 해제한 경우에만 발생합니다(이 이벤트가 완료될 때까지는 다른 단추를 이 포인터와 연결할 수 없음). 이 독점적인 연결 때문에 다른 마우스 단추 클릭은 PointerMoved 이벤트를 통해 라우트됩니다. 다음 예제와 같이 이 이벤트를 처리할 때 마우스 단추 상태를 테스트할 수 있습니다.

private void Target_PointerMoved(object sender, PointerRoutedEventArgs e)
{
    Windows.UI.Xaml.Input.Pointer ptr = e.Pointer;

    // Multiple, simultaneous mouse button inputs are processed here.
    // Mouse input is associated with a single pointer assigned when 
    // mouse input is first detected. 
    // Clicking additional mouse buttons (left, wheel, or right) during 
    // the interaction creates secondary associations between those buttons 
    // and the pointer through the pointer pressed event. 
    // The pointer released event is fired only when the last mouse button 
    // associated with the interaction (not necessarily the initial button) 
    // is released. 
    // Because of this exclusive association, other mouse button clicks are 
    // routed through the pointer move event.          
    if (ptr.PointerDeviceType == Windows.Devices.Input.PointerDeviceType.Mouse)
    {
        // To get mouse state, we need extended pointer details.
        // We get the pointer info through the getCurrentPoint method
        // of the event argument. 
        Windows.UI.Input.PointerPoint ptrPt = e.GetCurrentPoint(Target);
        if (ptrPt.Properties.IsLeftButtonPressed)
        {
            eventLog.Text += "\nLeft button: " + ptrPt.PointerId;
        }
        if (ptrPt.Properties.IsMiddleButtonPressed)
        {
            eventLog.Text += "\nWheel button: " + ptrPt.PointerId;
        }
        if (ptrPt.Properties.IsRightButtonPressed)
        {
            eventLog.Text += "\nRight button: " + ptrPt.PointerId;
        }
    }

    // Prevent most handlers along the event route from handling the same event again.
    e.Handled = true;

    // Display pointer details.
    updateInfoPop(e);
}
private void Target_PointerMoved(object sender, PointerRoutedEventArgs e)
{
    Windows.UI.Xaml.Input.Pointer ptr = e.Pointer;

    // Multiple, simultaneous mouse button inputs are processed here.
    // Mouse input is associated with a single pointer assigned when 
    // mouse input is first detected. 
    // Clicking additional mouse buttons (left, wheel, or right) during 
    // the interaction creates secondary associations between those buttons 
    // and the pointer through the pointer pressed event. 
    // The pointer released event is fired only when the last mouse button 
    // associated with the interaction (not necessarily the initial button) 
    // is released. 
    // Because of this exclusive association, other mouse button clicks are 
    // routed through the pointer move event.          
    if (ptr.PointerDeviceType == Windows.Devices.Input.PointerDeviceType.Mouse)
    {
        // To get mouse state, we need extended pointer details.
        // We get the pointer info through the getCurrentPoint method
        // of the event argument. 
        Windows.UI.Input.PointerPoint ptrPt = e.GetCurrentPoint(Target);
        if (ptrPt.Properties.IsLeftButtonPressed)
        {
            eventLog.Text += "\nLeft button: " + ptrPt.PointerId;
        }
        if (ptrPt.Properties.IsMiddleButtonPressed)
        {
            eventLog.Text += "\nWheel button: " + ptrPt.PointerId;
        }
        if (ptrPt.Properties.IsRightButtonPressed)
        {
            eventLog.Text += "\nRight button: " + ptrPt.PointerId;
        }
    }

    // Prevent most handlers along the event route from handling the same event again.
    e.Handled = true;

    // Display pointer details.
    updateInfoPop(e);
}

특정 이벤트에는 주로 해당 이벤트와만 관련된 다양한 포인터 디바이스 및 포인터 포인트 클래스에서 사용할 수 있는 정보가 있는 경우가 많습니다. 예를 들어 PointerWheelChanged를 처리할 때 PointerPointPropertiesMouseWheelDelta에 관심이 있을 수 있습니다.

GetCurrentPoint 및 GetIntermediatePoints 메서드에서 검색한 개체는 PointerPointProperties 개체를 가져오는 Properties 속성을 통해 확장 포인터 정보에 대한 액세스를 제공합니다.

다음 예제에서는 PointerPoint 및 PointerPointProperties 개체 를 통해 확장 포인터 속성을 가져옵니다. 전체 예제 는 빠른 시작: 포인터 를 참조하세요.

String queryPointer(PointerPoint ptrPt)
{
    String details = "";

    switch (ptrPt.PointerDevice.PointerDeviceType)
    {
        case Windows.Devices.Input.PointerDeviceType.Mouse:
            details += "\nPointer type: mouse";
            break;
        case Windows.Devices.Input.PointerDeviceType.Pen:
            details += "\nPointer type: pen";
            if (ptrPt.IsInContact)
            {
                details += "\nPressure: " + ptrPt.Properties.Pressure;
                details += "\nrotation: " + ptrPt.Properties.Orientation;
                details += "\nTilt X: " + ptrPt.Properties.XTilt;
                details += "\nTilt Y: " + ptrPt.Properties.YTilt;
                details += "\nBarrel button pressed: " + ptrPt.Properties.IsBarrelButtonPressed;
            }
            break;
        case Windows.Devices.Input.PointerDeviceType.Touch:
            details += "\nPointer type: touch";
            details += "\nrotation: " + ptrPt.Properties.Orientation;
            details += "\nTilt X: " + ptrPt.Properties.XTilt;
            details += "\nTilt Y: " + ptrPt.Properties.YTilt;
            break;
        default:
            details += "\nPointer type: n/a";
            break;
    }

    GeneralTransform gt = Target.TransformToVisual(page);
    Point screenPoint;

    screenPoint = gt.TransformPoint(new Point(ptrPt.Position.X, ptrPt.Position.Y));
    details += "\nPointer Id: " + ptrPt.PointerId.ToString() +
        "\nPointer location (parent): " + ptrPt.Position.X + ", " + ptrPt.Position.Y +
        "\nPointer location (screen): " + screenPoint.X + ", " + screenPoint.Y;
    return details;
}

일반적으로 이 메서드에서 반환된 개체는 포인터 데이터를 GestureRecognizer에 피드하는 데 사용됩니다. 다른 시나리오는 PointerWheelChanged 이벤트에 대한 MouseWheelDelta를 가져오는 것입니다. 이 값은 PointerPointProperties에 있습니다.

버전 기록

Windows 버전 SDK 버전 추가된 값
1709 16299 IsGenerated

속성

Handled

라우트된 이벤트를 처리됨으로 표시하는 값을 가져오거나 설정하며 이벤트 경로를 따라 있는 대부분의 처리기가 동일한 이벤트를 다시 처리하지 못하도록 합니다.

IsGenerated

포인터 이벤트가 사용자가 개체와 직접 상호 작용하여 발생했는지 또는 애플리케이션의 UI 변경 내용에 따라 플랫폼에서 생성되었는지 여부를 나타내는 값을 가져옵니다.

KeyModifiers

포인터 이벤트가 시작될 때 활성화된 키 한정자를 나타내는 값을 가져옵니다.

OriginalSource

이벤트를 발생시킨 개체에 대한 참조를 가져옵니다. 앱 UI에서 선언된 요소가 아닌 컨트롤의 템플릿 부분입니다.

(다음에서 상속됨 RoutedEventArgs)
Pointer

포인터 토큰에 대한 참조를 가져옵니다.

메서드

GetCurrentPoint(UIElement)

이벤트와 연결된 포인터에 대한 기본 정보를 제공하는 PointerPoint 개체를 검색합니다.

GetIntermediatePoints(UIElement)

마지막 포인터 이벤트부터 현재 포인터 이벤트까지의 포인터 기록을 나타내는 PointerPoint 개체의 컬렉션을 검색합니다. 컬렉션의 각 PointerPoint는 이벤트와 연결된 포인터에 대한 기본 정보를 제공합니다. 컬렉션의 마지막 항목은 GetCurrentPoint에서 반환된 PointerPoint 개체와 동일합니다.

적용 대상

추가 정보