xamlwebviewuwpc++-cxxbox-one

Why does XAML WebView Input Box not have cursor until I open/close Guide on XBox One?


OK, I've got a C++/CX/XAML UWP game running on Xbox One.

It has a SwapChainPanel containing a WebView for UI overlay and a Canvas where the game runs.

When I start up the Webview is fullscreen and the canvas isn't doing anything. The controller navigates the Web UI no problem, with up/down/left/right, 'a' for select and 'b' for back/suspend. This navigating is done using the JS Gamepad API, rather than mouse-mode.

The problem comes when I select an input field in the webview. I can highlight the box, I can press A, I can navigate away, but I do not get a cursor in the box and the soft keyboard does not appear. This is the problem; I can't enter anything in the input box.

If, however, I press the 'Xbox button' on the controller to bring up the Guide sidebar, then press the 'Xbox button' again to dismiss it suddenly a cursor appears in the selected input box and a press of 'a' brings up the soft keyboard and everything is fine. From this point on, any textbox I select works absolutely fine.

So, why doesn't it work when I first load the app? What am I not doing that I need to do?

I suspected a focus problem of some kind, but using a GotFocusEventHandler() to report focus events just showed the Webview getting the focus when the app started, and the same when coming back from the Guide sidebar. Forcing a call to webView->Focus(FocusState::Programmatic); when the input box was highlighted had no reported focus event, presumably because the webview was already the focus.

On further investigation the page works fine if I access it via an HTTP URL, but doesn't work if I use HTTPS. I can't see any obvious error messages, and both versions of the URL are present in the Content URIs section of the manifest


Solution

  • OK, after much investigation and many blind alleys the following code fixed this problem, which I have to assume is a bug in the Edge WebView.

    webView->Visibility = Visibility::Collapsed;  
    webView->Visibility = Visibility::Visible;    // Yes, I know I just changed this but it needs changing twice.
    webView->Focus(FocusState::Programmatic);
    

    If you miss any of these lines out the whole thing doesn't work.