UIElement.PointerReleased 事件

定义

在释放之前启动 按下 操作的指针设备时发生,同时在此元素中。 请注意, 不保证按下 操作的结尾会触发 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 应用中作为指针输入进行接收、处理和管理。 这些交互中的任何一个都可以生成 PointerReleased 事件。 有关详细信息,请参阅 处理指针输入

其他事件(而不是 PointerReleased)可能会在操作结束时触发,例如 PointerCanceledPointerCaptureLost。 不要依赖于 PointerPressed 和 PointerReleased 事件始终成对发生。 若要正常运行,你的应用必须侦听并处理代表 “按下” 操作可能结论的所有事件。 可能无法获得 PointerReleased 出现的一些原因包括:

  • 特定硬件处理触摸操作和 按下 操作的方式的差异
  • 从其他指针进行编程指针捕获
  • 用于更改显示区域关系的用户操作,例如更改分辨率或监视器设置
  • 输入交互,例如触笔触摸与上一个触摸操作相同的表面

最初触发 PointerReleased 事件的用户操作可能会导致 点击 事件,也可能在每个设备不同的条件下导致 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 支持将事件处理程序附加到将调用的路由,即使事件的事件数据标记为“ 已处理”也是如此。 请参阅 AddHandler

特定Windows 运行时控件可能对 PointerReleased 输入事件具有基于类的处理。 如果是这样,控件可能具有 OnPointerReleased 方法的替代。 通常,事件被标记为由类处理程序处理,并且不会引发 PointerReleased 事件,以便由该控件上的任何用户代码处理程序进行处理。 有关事件基于类的处理工作原理的详细信息,请参阅 事件和路由事件概述

控件还可以具有独立于事件运行的 PointerUpThemeAnimation 个性动画。

适用于

另请参阅