UIElement.PointerPressed イベント

定義

ポインター デバイスがこの要素内で Press アクションを開始したときに発生します。

public:
 virtual event PointerEventHandler ^ PointerPressed;
// Register
event_token PointerPressed(PointerEventHandler const& handler) const;

// Revoke with event_token
void PointerPressed(event_token const* cookie) const;

// Revoke with event_revoker
UIElement::PointerPressed_revoker PointerPressed(auto_revoke_t, PointerEventHandler const& handler) const;
public event PointerEventHandler PointerPressed;
function onPointerPressed(eventArgs) { /* Your code */ }
uIElement.addEventListener("pointerpressed", onPointerPressed);
uIElement.removeEventListener("pointerpressed", onPointerPressed);
- or -
uIElement.onpointerpressed = onPointerPressed;
Public Custom Event PointerPressed As PointerEventHandler 
<uiElement PointerPressed="eventhandler"/>

イベントの種類

注釈

タッチ、マウス、ペン/スタイラスの操作は、UWP アプリでポインター入力として受信、処理、管理されます。 これらの操作では、PointerPressed イベントを生成できます。 詳細については、「 ポインター入力を処理する」を参照してください。 ポインター イベントは、複数のポインターとそのリレーションシップに関心があるシナリオ、または正確な座標位置などの各ポインターの詳細を調べる場合に使用します。 それ以外の場合は、 タップなどのジェスチャ イベントを処理することを検討してください。

PointerEventHandler に基づくハンドラーを使用して、このイベントを処理します。

マウス入力が最初に検出されると、割り当てられている単一ポインターと関連付けられます。 マウス ボタン (左ボタン、ホイール、または右ボタン) をクリックすると、PointerPressed イベントによってポインターとそのボタンの間に 2 番目の関連付けが行われます。 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);
}

マウス入力デバイスからのポインター イベントは、通常、アプリの有効期間のイベントの詳細で同じ PointerId を 持ちます。

PointerPressed はルーティング イベントです。 ルーティング イベントの概念の詳細については、「 イベントとルーティング イベントの概要」を参照してください。

タッチ操作や、タッチ操作の結果に発生する対話/操作イベントについては、ヒット テストで要素が表示されない場合、イベント ソースとして使用したり、操作に関連付けられたイベントを起動することはできません。 UIElement.VisibilityVisible である必要があります。 派生型の他のプロパティも、ヒット テストの可視性に影響します。 詳しくは、「イベントとルーティング イベントの概要」をご覧ください。

PointerPressed では、イベントのイベント データが Handled とマークされている場合でも呼び出されるルートにイベント ハンドラーをアタッチする機能がサポートされています。 「 AddHandler」を参照してください。

特定のWindows ランタイム コントロールには、PointerPressed 入力イベントに対するクラスベースの処理が含まれる場合があります。 その場合、コントロールには OnPointerPressed メソッドのオーバーライドが含まれている可能性があります。 通常、イベントはクラス ハンドラーによって処理済みとしてマークされ、PointerPressed イベントは、そのコントロール上のユーザー コード ハンドラーによって処理するために発生しません。 たとえば、 ButtonBase には PointerPressed を処理するクラス処理があり、代わりに Click を起動 します。 イベントのクラスベースの処理のしくみの詳細については、「 イベントとルーティング イベントの概要」を参照してください。

コントロールには、イベントとは無関係に実行される PointerDownThemeAnimation パーソナリティ アニメーションを含めることもできます。

ポインター キャプチャ

PointerPressed は、ポインターをキャプチャするときに開始イベントとして使用される場合があるため、ポインターがダウンしている限り、ポインター関連のイベントはすべて特定の要素によってキャプチャされます。 ポインターをキャプチャするには、キャプチャを維持する必要がある特定の UI 要素で CapturePointer メソッドを呼び出します。 これは通常、PointerPressed イベント ハンドラー内で行われ、イベントの送信者に 対して CapturePointer を呼び出 します。 ポインターをキャプチャする方法とその理由の詳細については、「 CapturePointer」を参照してください。

PointerPressed イベントとジェスチャ イベント、または操作イベント

PointerPressed イベントを最初に発生するユーザー アクションは、入力デバイスがマウスでない限り、最終的に Hold ジェスチャを表す Hold イベントになる可能性があります。 PointerPressed が発生する要素に既定以外の ManipulationMode 値がある場合、そのアクションによって ManipulationStarted などのさまざまな操作イベントが発生する可能性もあります。 詳細については、「 ポインター入力を処理する」の「操作イベントの使用」セクションを参照してください。

PointerPressed が起動すると、イベントを発生させる前に、Holding 以外のジェスチャ イベントがポインターの解放を待機しているため、Tapped などのジェスチャ イベントはまだ発生しません。

アプリのユーザー操作の一般的な設計規則として、操作に対応できるコントロール固有のイベントがあるかどうか、または適切なジェスチャ イベントがあるかどうかを調べる必要があります。 たとえば、コントロールが Button の場合、そのコントロールには、ユーザーがボタンのアクションを呼び出すときに特に目的とする Click イベントがあります。 または、要素がボタンではなく、要素の主なアクションの と イベントを処理している場合は、 Tapped を処理します。

ジェスチャ イベントは、 IsTapEnabled などのプロパティを設定することで、個々の要素で明示的に無効にすることができます。 操作を処理している場合はジェスチャ イベントを無効にすることができますが、ポインター イベントを処理している場合は通常、ジェスチャ イベントを無効にする必要はありません。 ポインター イベントを明示的に無効にすることはできませんが、それらを処理しないことを選択できます。

PointerPressed と PointerReleased

PointerReleased ではなく他のイベントは、アクションの最後に発生する可能性があります (PointerCanceledPointerCaptureLost など)。 PointerPressed イベントと PointerReleased イベントが常にペアで発生することに依存しないでください。 適切に機能するには、アプリで Press アクションに対する結論を表す可能性のあるすべてのイベントをリッスンして処理する必要があります。 PointerReleased が発生しない理由の一部を次に示します。

  • 特定のハードウェアがタッチ アクションと プレス アクションを処理する方法の違い
  • 別のポインターからのプログラム ポインター キャプチャ
  • 解像度やモニターの設定の変更など、表示領域の関係を変更するユーザー アクション
  • 前のタッチ アクションと同じサーフェスに触れるスタイラスなどの入力操作

適用対象

こちらもご覧ください