共用方式為


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 事件時,使用者手指或滑鼠指標的視窗) 座標 (。 功能表會放在上方並置中於這一點。

注意

對於 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 來識別及處理叫用的命令。

備註

您可以看到完整的程式代碼範例,示範如何在 操作功能表範例中建立和自定義操作功能表。

適用於

另請參閱