Share via


PopupMenu.ShowAsync(Point) 方法

定义

显示指定客户端坐标处的上下文菜单。

public:
 virtual IAsyncOperation<IUICommand ^> ^ ShowAsync(Point invocationPoint) = ShowAsync;
IAsyncOperation<IUICommand> ShowAsync(Point const& invocationPoint);
public IAsyncOperation<IUICommand> ShowAsync(Point invocationPoint);
function showAsync(invocationPoint)
Public Function ShowAsync (invocationPoint As Point) As IAsyncOperation(Of IUICommand)

参数

invocationPoint
Point

触发 oncontextmenu 事件时,相对于用户手指或鼠标指针的窗口,DIP 中) (坐标。 菜单位于此点的上方并居中。

注意

对于 VB、C# 和 C++,此窗口是与调用上下文菜单的线程关联的 CoreWindow

返回

一个 IUICommand 对象,该对象表示在 ShowAsync 调用完成后由用户调用的上下文菜单命令。

如果未调用任何命令,则 ShowAsync 返回 null

示例

在显示上下文菜单之前,必须为 oncontextmenu 事件添加事件侦听器。 例如, 上下文菜单示例 侦听特定 HTML 元素上的 事件,然后调用 scenario1AttachmentHandler 函数。

document.getElementById("attachment").addEventListener("contextmenu", attachmentHandler, false);
menu.commands.append(new Windows.UI.Popups.UICommand("Save attachment", onSaveAttachment));

// We don't want to obscure content, so pass in the position representing the selection area.
// We registered command callbacks; no need to handle the menu completion event
menu.showAsync(pageToWinRT(e.pageX, e.pageY)).then(function (invokedCommand) {
    if (invokedCommand === null) {
        // The command is null if no command was invoked.
        WinJS.log && WinJS.log("Context menu dismissed", "sample", "status");
    }
});

此外,请确保检查调用了命令,并根据需要为应用处理该情况。 如果调用的 UICommand 在示例) onSaveAttachment 中具有 (回调函数,则将执行回调函数。 否则,可能需要使用 UICommand.Id 来标识和处理调用的命令。

注解

可以在 上下文菜单示例中查看演示如何创建和自定义上下文菜单的完整代码示例。

适用于

另请参阅