Table of Contents

Class CoreWebView2ContextMenuRequestedEventArgs

Namespace
Microsoft.Web.WebView2.Core
Assembly
Microsoft.Web.WebView2.Core.dll

Event args for the ContextMenuRequested event.

public class CoreWebView2ContextMenuRequestedEventArgs : EventArgs
Inheritance
CoreWebView2ContextMenuRequestedEventArgs
Inherited Members

Remarks

Will contain the selection information and a collection of all of the default context menu items that the WebView would show. Allows the app to draw its own context menu or add/remove from the default context menu.

Properties

ContextMenuTarget

Gets the target information associated with the requested context menu.

public CoreWebView2ContextMenuTarget ContextMenuTarget { get; }

Property Value

CoreWebView2ContextMenuTarget
See Also

Handled

Gets or sets whether the ContextMenuRequested event is handled by host after the event handler completes or after the deferral is completed if there is a taken CoreWebView2Deferral.

public bool Handled { get; set; }

Property Value

bool

Remarks

If Handled is set to true then WebView2 will not display a context menu and will instead use the SelectedCommandId property to indicate which, if any, context menu item to invoke. If after the event handler or deferral completes, Handled is set to false then WebView will display a context menu based on the contents of the MenuItems property. The default value is false.

Location

Gets the coordinates where the context menu request occurred in relation to the upper left corner of the WebView bounds.

public Point Location { get; }

Property Value

Point

MenuItems

Gets the collection of CoreWebView2ContextMenuItem objects.

public IList<CoreWebView2ContextMenuItem> MenuItems { get; }

Property Value

IList<CoreWebView2ContextMenuItem>

SelectedCommandId

Gets or sets the selected CoreWebView2ContextMenuItem's CommandId.

public int SelectedCommandId { get; set; }

Property Value

int

Remarks

When the app handles the ContextMenuRequested event, it can set this to report the selected command from the context menu. The default value is -1 which means that no selection occurred. The app can also set the command ID for a custom context menu item, which will cause the CustomItemSelected event to be fired, however while command IDs for each custom context menu item is unique during a ContextMenuRequested event, WebView may reassign command ID values of deleted custom ContextMenuItems to new objects and the command ID assigned to the same custom item can be different between each app runtime. The command ID should always be obtained via the CommandId property.

Methods

GetDeferral()

Returns a CoreWebView2Deferral object.

public CoreWebView2Deferral GetDeferral()

Returns

CoreWebView2Deferral

Remarks

Use this operation to complete the event when the custom context menu is closed.