-api-id | -api-type |
---|---|
M:Windows.UI.Popups.PopupMenu.ShowForSelectionAsync(Windows.Foundation.Rect,Windows.UI.Popups.Placement) |
winrt method |
Shows the context menu in the preferred placement relative to the specified selection.
The coordinates (in DIPs) of the selected rectangle, relative to the window.
Note
For VB, C#, and C++, this window is the CoreWindow associated with the thread that is calling the context menu.
The preferred placement of the context menu relative to the selection rectangle.
The context menu is positioned in the preferredPlacement if the menu fits in the window and does not cover the selection. If the context menu does not fit in the preferred placement, another placement that does not cover the selection is used. If the context menu does not fit anywhere else, a placement that partially or wholly covers the selection is used.
A IUICommand object that represents the context menu command invoked by the user, after the ShowForSelectionAsync call completes.
If no command is invoked, ShowForSelectionAsync returns null.
You can see complete code examples that demonstrate how to create and customize context menus in the Context menu sample.
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.
[!code-jsaddcontextmenueventlistener_js]
[!code-jsselectionrect_js]
Adding context menus, Context menu sample, Guidelines and checklist for , IUICommand, oncontextmenu, Rect, ShowForSelectionAsync(Rect), UICommand