Commands | commands property
Collapse the table of content
Expand the table of content

PopupMenu.Commands | commands property

Gets the commands for the context menu.

Syntax


var commands = popupMenu.commands;

Property value

Type: IVector<IUICommand> [JavaScript/C++] | System.Collections.Generic.IList<IUICommand> [.NET]

The commands for the context menu.

Remarks

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.

Examples

Add your commands to the context menu after you create a new PopupMenu. Create a UICommand object for each command and append the commands to the context menu.

The Context menu sample creates and appends a new UICommand that specifies a handler function, which runs if the command is invoked.


menu.commands.append(new Windows.UI.Popups.UICommand("Open with", onOpenWith));


The signature of a handler function for a command (like the onOpenWith function in the example) is described by UICommandInvokedHandler.

The Context menu sample also creates and appends a new UICommand that specifies a command identifier, which can be used to determine the command that has been invoked.


menu.commands.append(new Windows.UI.Popups.UICommand("Copy", null, 1));


If you want your context menu to have a separator between commands, create and append a UICommandSeparator between the commands where you want the separator to appear.

The Context menu sample places a separator between its "Copy" and "Highlight" commands like this.


menu.commands.append(new Windows.UI.Popups.UICommand("Copy", null, 1));
menu.commands.append(new Windows.UI.Popups.UICommandSeparator);
menu.commands.append(new Windows.UI.Popups.UICommand("Highlight", null, 2));
menu.commands.append(new Windows.UI.Popups.UICommand("Look up", null, 3));


Requirements (Windows 10 device family)

Device family

Universal, introduced version 10.0.10240.0

API contract

Windows.Foundation.UniversalApiContract, introduced version 1.0

Namespace

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

Metadata

Windows.Foundation.UniversalApiContract.winmd

Requirements (Windows 8.x and Windows Phone 8.x)

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

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
IUICommand
IVector(IUICommand)
PopupMenu
PopupMenu.PopupMenu
UICommand
UICommandInvokedHandler
UICommandSeparator

 

 

Show:
© 2017 Microsoft