UIElement.PointerReleased 事件

定義

發生于先前起始 「按下」 動作的指標裝置釋放時,同時在此元素內。 請注意, Press 動作的結尾不保證會引發 PointerReleased 事件;其他事件可能會改為引發。 如需詳細資訊,請參閱。

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

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

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

事件類型

備註

觸控、滑鼠和手寫筆/手寫筆互動會在 UWP app 中接收、處理及管理為指標輸入。 上述任何互動都可以產生 PointerReleased 事件。 如需詳細資訊,請參閱 處理指標輸入

其他事件,而不是 PointerReleased 可能會在動作結尾引發,例如 PointerCanceledPointerCaptureLost。 請勿依賴 PointerPressed 和 PointerReleased 事件一律以配對方式發生。 若要正常運作,您的應用程式必須接聽並處理代表 Press 動作可能結論的所有事件。 您可能未收到 PointerReleased 的一些原因如下:

  • 特定硬體如何處理觸控動作和 按下 動作的差異
  • 從不同的指標擷取程式設計指標
  • 變更顯示區域關聯性的使用者動作,例如變更解析度或監視設定
  • 輸入互動,例如觸控與先前觸控動作相同表面的手寫筆

一開始引發 PointerReleased 事件的使用者動作可能會導致 Tapped 事件,或也可能在每個裝置不同的狀況下產生 RightTapped 。 如需詳細資訊,請參閱 點選RightTapped

滑鼠輸入會與第一次偵測到滑鼠輸入時指派的單一指標相關聯。 按一下滑鼠按鈕 (左鍵、滾輪或右鍵) 會透過 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);
}

PointerReleased 是路由事件。 如需路由事件概念的詳細資訊,請參閱 事件和路由事件概觀

對於觸控動作以及因為觸控動作而引發的互動特定或操作事件,元素必須具有點擊測試可見性,才能成為事件來源並引發與動作相關聯的事件。 UIElement.Visibility 必須是 Visible。 衍生類型的其他屬性也會影響點擊測試可見度。 如需詳細資訊,請參閱事件與路由事件概觀

PointerReleased 支援將事件處理常式附加至將叫用的路由,即使事件的事件資料標示為 Handled 也一樣。 請參閱 AddHandler

特定Windows 執行階段控制項可能有 PointerReleased 輸入事件的類別型處理。 如果是,控制項可能具有 OnPointerReleased方法的覆寫。 事件通常會由類別處理常式標示為已處理,而且不會引發 PointerReleased 事件,以供該控制項上的任何使用者程式碼處理常式處理。 如需事件類別型處理運作方式的詳細資訊,請參閱 事件和路由事件概觀

控制項也可能有 PointerUpThemeAnimation 個人化動畫,該動畫會獨立于事件執行。

適用於

另請參閱