Environment: Windows 10 Pro - ver. 1903
, VS2019 latest version
, WPF Core
When I have a manual control on an HTML
page displayed inside WebView2 control, I can disable the context menu by simply adding oncontextmunu={return false;}
as an attribute to <body>
tag. But in most cases the web page is displayed based on user interaction (what page user navigates to etc.).
Question: How can we disable to context menu of a webpage displayed in WebView2 control?
Remarks:
- I have noticed that in some cases where a JavaScript is loaded along with a webpage, the
oncontextmunu={return false;}
does not disable the context menu even if I add this attribute programmatically to thebody
tag of loaded page. I seeAreDefaultContextMenusEnabled
property of Microsoft.Web.WebView2.Core.CoreWebView2Settings class butVS2019
does not recognize any such property forWebView2
. - There was a similar issue on the old
WebBrowser
control of WPF as described here and here, and I have the similar situation for WebView2. - According to bullet 5 of this Microsoft link the issue was resolved. But the solution there seems to be related to
C++
while I'm usingC#
. Maybe, there is an alternative.