My solution, put a grid with almost transparent background after WebView
How to disable user interaction with a WebView (Windows.UI.Xaml.Controls)
Hi,
I would like to know how to disable all user interaction with a WebView component in a UWP project.
I have tried to cancel the GettingFocus event, to no avail.
It should also disable the user interaction when running on an xbox.
How can I disable all user interaction, keyboard, mouse, xbox hand controller?
2 answers
Sort by: Most helpful
-
macintoshpro 36 Reputation points
2020-01-08T04:39:15.62+00:00 -
Richard Zhang-MSFT 6,936 Reputation points
2019-12-09T05:54:26.557+00:00 Hello,
Welcome to our Microsoft Q&A platform!
In
WebView
, there is no API to disable user-web page interaction.But we can inject Javascript to add a layer of invisible mask to Html document to prevent user interaction.
We can listen to the
WebView.LoadCompleted
event and perform the following processing:private async void WebView_LoadCompleted(object sender, NavigationEventArgs e) { var webView = sender as WebView; var height = await webView.InvokeScriptAsync("eval", new string[] { "document.body.scrollHeight.toString()" }); string script = "var body=document.body;" + "var temp = document.createElement('div'); " + $"temp.style=\"height:{height}px; width:100%; background:transparent;position:absolute;top:0;left:0;z-index:9999;\";" + "body.appendChild(temp)"; await webView.InvokeScriptAsync("eval", new string[] { script }); }
Thanks.