共用方式為


CoreWebView2ContextMenuRequestedEventArgs Class

Event args for the CoreWebView2.ContextMenuRequested event. 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.

Summary

Members Description
ContextMenuTarget Gets the target information associated with the requested context menu.
Handled Gets or sets whether the CoreWebView2.ContextMenuRequested event is handled by host after the event handler completes or after the deferral is completed if there is a taken Deferral.
Location Gets the coordinates where the context menu request occurred in relation to the upper left corner of the WebView bounds.
MenuItems Gets the collection of CoreWebView2ContextMenuItem objects.
SelectedCommandId Gets or sets the selected CoreWebView2ContextMenuItem's CoreWebView2ContextMenuItem.CommandId.
GetDeferral Returns a Deferral object.

Properties

ContextMenuTarget

readonly CoreWebView2ContextMenuTarget ContextMenuTarget

Gets the target information associated with the requested context menu.

Handled

bool Handled

Gets or sets whether the CoreWebView2.ContextMenuRequested event is handled by host after the event handler completes or after the deferral is completed if there is a taken Deferral. If Handled is set to true then WebView2 will not display a context menu and will instead use the CoreWebView2ContextMenuRequestedEventArgs.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 CoreWebView2ContextMenuRequestedEventArgs.MenuItems property. The default value is false.

Location

readonly Point Location

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

readonly IVector<CoreWebView2ContextMenuItem> MenuItems

Gets the collection of CoreWebView2ContextMenuItem objects.

SelectedCommandId

int SelectedCommandId

Gets or sets the selected CoreWebView2ContextMenuItem's CoreWebView2ContextMenuItem.CommandId. When the app handles the CoreWebView2.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 CoreWebView2ContextMenuItem.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 CoreWebView2ContextMenuItem.CommandId property.

Methods

GetDeferral

Deferral GetDeferral()

Returns a Deferral object. Use this operation to complete the event when the custom context menu is closed.

Referenced by