How to disable user interaction with a WebView (Windows.UI.Xaml.Controls)

Snorvarg 6 Reputation points


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?

Universal Windows Platform (UWP)
{count} vote

2 answers

Sort by: Most helpful
  1. macintoshpro 36 Reputation points

    My solution, put a grid with almost transparent background after WebView

    2 people found this answer helpful.
    0 comments No comments

  2. Richard Zhang-MSFT 6,936 Reputation points


    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'); " +  
            $"\"height:{height}px; width:100%; background:transparent;position:absolute;top:0;left:0;z-index:9999;\";" +  
        await webView.InvokeScriptAsync("eval", new string[]  


    1 person found this answer helpful.
    0 comments No comments