Represents a context menu.
Syntax
var popupMenu = new Windows.UI.Popups.PopupMenu();
Attributes
- ActivatableAttribute(NTDDI_WIN8)
- MarshalingBehaviorAttribute(Standard)
- MuseAttribute()
- VersionAttribute(NTDDI_WIN8)
Members
The PopupMenu class has these types of members:
Constructors
The PopupMenu class has these constructors.
| Constructor | Description |
|---|---|
| PopupMenu | Creates a new instance of the PopupMenu class. |
Methods
The PopupMenu class has these methods. With C#, Visual Basic, and C++, it also inherits methods from the Object class.
| Method | Description |
|---|---|
| ShowAsync | Shows the context menu at the specified client coordinates. |
| ShowForSelectionAsync(Rect) | Shows the context menu above the specified selection. |
| ShowForSelectionAsync(Rect, Placement) | Shows the context menu in the preferred placement relative to the specified selection. |
Properties
The PopupMenu class has these properties.
| Property | Access type | Description |
|---|---|---|
| Read-only | Gets the commands for the context menu. |
Remarks
Context menus can show a maximum of six commands. This limit helps to ensure that the context menu remains uncluttered, usable, and directly relevant to users.
You can see complete code examples that demonstrate how to create and customize context menus in the Context menu sample on the Windows Store app sample home page.
Note : This class is not agile, which means that you need to consider its threading model and marshaling behavior. For more info, see Threading and Marshaling (C++/CX) and Using Windows Runtime objects in a multithreaded environment (.NET).
Examples
Provide users with a context menu by adding an event listener for the "contextmenu" event. For example, the Context menu sample listens for the event on specific HTML elements, and then calls the scenario1AttachmentHandler function.
document.getElementById("scenario1Attachment").addEventListener("contextmenu", /*@static_cast(EventListener)*/scenario1AttachmentHandler, false);
document.getElementById("attachment").addEventListener("contextmenu", attachmentHandler, false);
When you add a "contextmenu" event listener, the default context menu is used. The default menu provides limited commands for selected text or hyperlinks (learn more in Adding context menus).
To customize the context menu, call preventDefault on the event to suppress the default, and then create a new, empty context menu menu as shown in the Context menu sample.
e.preventDefault(); // Prevent the default context menu
e.preventDefault(); // Prevent the default context menu.
var menu = new Windows.UI.Popups.PopupMenu();
var menu = new Windows.UI.Popups.PopupMenu();
Use popupMenu.commands to add commands to your context menu.
Requirements
|
Minimum supported client | Windows 8 [Windows Store apps only] |
|---|---|
|
Minimum supported server | Windows Server 2012 [Windows Store apps only] |
|
Namespace |
|
|
Metadata |
|
See also
- Adding context menus
- Context menu sample
- Guidelines and checklist for context menus
- Reference
- PopupMenu.Commands
- UICommand
- UICommandSeparator
Build date: 2/25/2013