PopupMenu.ShowAsync(Point) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Shows the context menu at the specified client coordinates.
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)
Parameters
- invocationPoint
- Point
The coordinates (in DIPs), relative to the window, of the user's finger or mouse pointer when the oncontextmenu event fired. The menu is placed above and centered on this point.
Note
For VB, C#, and C++, this window is the CoreWindow associated with the thread that is calling the context menu.
Returns
A IUICommand object that represents the context menu command that was invoked by the user, after the ShowAsync call completes.
If no command is invoked, ShowAsync returns null.
Examples
Before you can show a context menu, you must add an event listener for the oncontextmenu event. For example, the Context menu sample listens for the event on specific HTML elements, and then calls the scenario1AttachmentHandler
function.
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");
}
});
Additionally, make sure you check that a command was invoked and process that case as appropriate for your app. If the UICommand that is invoked has a callback function (onSaveAttachment
in the example), the callback function will be executed. Otherwise, you may need to use UICommand.Id to identify and process the invoked command.
Remarks
You can see complete code examples that demonstrate how to create and customize context menus in the Context menu sample.