Jaa


PopupMenu Class

Definition

Represents a context menu.

In a desktop app, before using an instance of this class in a way that displays UI, you'll need to associate the object with its owner's window handle. For more info, and code examples, see Display WinRT UI objects that depend on CoreWindow.

public ref class PopupMenu sealed
/// [Windows.Foundation.Metadata.Activatable(65536, Windows.Foundation.UniversalApiContract)]
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Standard)]
class PopupMenu final
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Standard)]
/// [Windows.Foundation.Metadata.Activatable(65536, "Windows.Foundation.UniversalApiContract")]
class PopupMenu final
[Windows.Foundation.Metadata.Activatable(65536, typeof(Windows.Foundation.UniversalApiContract))]
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Standard)]
public sealed class PopupMenu
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Standard)]
[Windows.Foundation.Metadata.Activatable(65536, "Windows.Foundation.UniversalApiContract")]
public sealed class PopupMenu
function PopupMenu()
Public NotInheritable Class PopupMenu
Inheritance
Object Platform::Object IInspectable PopupMenu
Attributes

Windows requirements

Device family
Windows 10 (introduced in 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v1.0)

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);

To customize the context menu, call preventDefault on the event to suppress the default, and then create a new, empty context menu as shown in the Context menu sample.

e.preventDefault(); // Prevent the default context menu.
var menu = new Windows.UI.Popups.PopupMenu();

Remarks

A context menu 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 menu in the Context menu sample (Windows 10) and Context menu sample (Windows 8.1).

For XAML-based desktop applications, we recommend to use a menu flyout to implement context menus.

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

Constructors

PopupMenu()

Creates a new instance of the PopupMenu class.

In a desktop app, before using an instance of this class in a way that displays UI, you'll need to associate the object with its owner's window handle. For more info, and code examples, see Display WinRT UI objects that depend on CoreWindow.

Properties

Commands

Gets the commands for the context menu.

Methods

ShowAsync(Point)

Shows the context menu at the specified client coordinates.

ShowForSelectionAsync(Rect, Placement)

Shows the context menu in the preferred placement relative to the specified selection.

ShowForSelectionAsync(Rect)

Shows the context menu above the specified selection.

Applies to

See also