UIElement.PointerMoved 事件

定義

當指標在指標保留在這個專案的點擊測試區域中時移動時發生。

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

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

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

事件類型

備註

觸控、滑鼠和手寫筆/手寫筆互動會在 UWP 應用程式中接收、處理及管理為指標輸入。 這些互動中的任何一個都可以產生 PointerMoved 事件。 For more info, see Handle pointer input and the "PointerMoved for mouse and stylus input" section of this topic.

在某些 UI 案例中,特別是當使用者使用滑鼠時,此事件將會引發許多。 請注意您放入此處理程式之程式碼的效能設定檔,並考慮使用您自己的旗標或容錯方式,以節流邏輯實際需要執行的次數。

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

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

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

滑鼠和手寫筆輸入的 PointerMoved

滑鼠輸入裝置具有螢幕上的游標,每當滑鼠移動至元素的界限時,即使沒有按下滑鼠按鍵,仍會顯示。 類似的行為適用于手寫筆裝置輸入,其中輸入裝置可以偵測手寫筆停留在輸入裝置介面上,但不會觸碰到它。 因此,滑鼠和手寫筆輸入會比觸控輸入更頻繁地引發 PointerMoved 事件。 如需詳細資訊,請參閱互動

相反地,只有在手指觸碰表面時,才能偵測到觸控點。 觸控點只會在觸控點移動時,產生 PointerMoved。 針對產生 PointerMoved 的這類觸控動作,也可能是動作會以操作或手勢處理。 如需詳細資訊,請參閱 處理指標輸入

滑鼠輸入與第一次偵測到滑鼠輸入時指派的單一指標相關聯,而且所有滑鼠起始的互動都有相同的 PointerId。 按一下滑鼠按鈕 (左鍵、滾輪或右鍵) 會透過 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);
}

某些應用程式,例如遊戲,需要追蹤特定功能的相對滑鼠移動 (,例如虛擬追蹤球或檢視相機) ,且不使用系統游標或絕對螢幕座標。 如需隱藏滑鼠游標並忽略絕對滑鼠資料的詳細資訊,請參閱 相對滑鼠移動和 CoreWindow

適用於

另請參閱