PopupMenu class

Applies to Windows and Windows Phone

Represents a context menu.

Syntax


public sealed class PopupMenu

Attributes

[MarshalingBehavior(Standard)]
[Muse()]
[Version(0x06020000)]

Members

The PopupMenu class has these types of members:

Constructors

The PopupMenu class has these constructors.

ConstructorDescription
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.

MethodDescription
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.

PropertyAccess typeDescription

Commands

Read-onlyGets 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("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.



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]

Minimum supported phone

Windows Phone 8.1 [Windows Runtime apps only]

Namespace

Windows.UI.Popups
Windows::UI::Popups [C++]

Metadata

Windows.winmd

See also

Adding context menus
Context menu sample
Guidelines and checklist for context menus
Reference
PopupMenu.Commands
UICommand
UICommandSeparator

 

 

Show:
© 2014 Microsoft