[WinRT Trick] Scrolling and Webview NavigateToString bug

If you add on a WinRT page a Webview and call NavigateToString method, you will lose wheel mouse scrolling on the entire page. Reason is simple, WebView isn’t really a control and doesn’t have a Focus() method. So at the end of a NavigateToString call, it will automatically take the focus and capture the mouse wheel. There are a few workarounds for this. I used this one:

   private void WebView_GotFocus(object sender, RoutedEventArgs e)
   {
      anotherControl.Focus(Windows.UI.Xaml.FocusState.Pointer);
   }

You can also use FocusManager to decide where you want the focus.
Bad point is that it is impossible to give the focus back to the WebView onces you took it away so the mouse wheel won’t scroll the WebView’s content.
You can find more information on this bug and some other workarounds on this MSDN forum thread

I lost a lot of time on a complex page to find this so think about it when you have scrolling problems.
Of course, if you have a better workaround, feel free to comment here I’d be happy to have a prettier solution :)

Advertisements
This entry was posted in WinRT and tagged , , , , . Bookmark the permalink.

Answer

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s