PointerRoutedEventArgs クラス

定義

最後のポインター イベント メッセージによって返される引数を格納します。

public ref class PointerRoutedEventArgs sealed : RoutedEventArgs
/// [Windows.Foundation.Metadata.ContractVersion(Microsoft.UI.Xaml.WinUIContract, 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(Microsoft.UI.Xaml.WinUIContract), 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
属性

次のコード例は 、入力サンプルのシナリオ 2 を示しています。 このコードでは、PointerPressed、PointerReleasedPointerEnteredPointerExitedPointerMoved の各イベントを使用した直接操作の使用パターンをいくつか示します。

<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;
}

注釈

ほとんどの場合、ポインター イベント ハンドラーのイベント引数を使用してポインター情報を取得することをお勧めします。

イベント引数でアプリに必要なポインターの詳細が本質的に公開されない場合は、 の GetCurrentPoint メソッドと GetIntermediatePoints メソッドPointerRoutedEventArgsを使用して拡張ポインター データにアクセスできます。 これらのメソッドを使用して、ポインター データのコンテキストを指定します。

PointerRoutedEventArgsイベント データ クラスは、次のイベントに使用されます。

重要

マウス入力が最初に検出されると、割り当てられている単一ポインターと関連付けられます。 マウス ボタン (左ボタン、ホイール、または右ボタン) をクリックすると、PointerPressed イベントによってポインターとそのボタンの間に 2 番目の関連付けが行われます。 PointerReleased イベントは、同じマウス ボタンを離したときにだけ発生します (イベントが完了するまではそのポインターに他のボタンが関連付けられることはありません)。 この排他的な関連付けのために、他のマウス ボタンをクリックした場合は、PointerMoved イベントによってルーティングされます。 次の例に示すように、このイベントを処理するときにマウス ボタンの状態をテストできます。

private void Target_PointerMoved(object sender, PointerRoutedEventArgs e)
{
    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 == PointerDeviceType.Mouse)
    {
        // To get mouse state, we need extended pointer details.
        // We get the pointer info through the getCurrentPoint method
        // of the event argument. 
        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 に関心がある場合があります。

メソッドおよび GetIntermediatePoints メソッドによってGetCurrentPoint取得される オブジェクトは、PointerPointProperties オブジェクトを取得する Properties プロパティを介して拡張ポインター情報にアクセスできます。

次の例では、PointerPoint オブジェクトと PointerPointProperties オブジェクトを使用して拡張ポインター プロパティを取得します。 (完全な例については、「 ポインター入力を処理 する」を参照してください)。

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

    switch (ptrPt.PointerDeviceType)
    {
        case PointerDeviceType.Mouse:
            details += "\nPointer type: mouse";
            break;
        case 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 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(panel);
    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 にフィードするために使用されます。 もう 1 つのシナリオは、PointerWheelChanged イベントの MouseWheelDelta を取得することです。その値は PointerPointProperties にあります

プロパティ

Handled

ルーティング イベントを処理済みとしてマークし、イベント ルートに沿ったほとんどのハンドラーが同じイベントを再び処理できないようにする値を取得または設定します。

IsGenerated

ポインター イベントがユーザーによるオブジェクトとの直接の対話から発生したか、アプリケーションの UI の変更に基づいてプラットフォームによって生成されたかを示す値を取得します。

KeyModifiers

ポインター イベントが開始された時点でアクティブだったキー修飾子を示す値を取得します。

OriginalSource

イベントを発生させたオブジェクトへの参照を取得します。 これは多くの場合、アプリ UI で宣言された要素ではなく、コントロールのテンプレート部分です。

(継承元 RoutedEventArgs)
Pointer

ポインター トークンへの参照を取得します。

メソッド

GetCurrentPoint(UIElement)

イベントに関連付けられているポインターに関する基本情報を提供する PointerPoint オブジェクトを取得します。

GetIntermediatePoints(UIElement)

ポインター履歴を表す PointerPoint オブジェクトのコレクションを、最後のポインター イベントから現在のポインター イベントまで、および現在のポインター イベントまで取得します。 コレクション内の各 PointerPoint は、イベントに関連付けられているポインターに関する基本情報を提供します。 コレクション内の最後の項目は、GetCurrentPoint によって返される PointerPoint オブジェクトと同じです。

適用対象

こちらもご覧ください