XBoxReveal HTML5 Windows Phone Sample: WebBrowser Control

May 6, 2013 — 1 Comment

In this third installment of the Windows Phone HTML5 XBox Reveal sample, we’ll look at fixing the horizontal and vertical scrolling of the index.html

Here are the first articles available if you have not read them yet for some background

  1. HTML5 & Windows Phone: XBox Reveal Sample
  2. HTML5 & Windows Phone: Multiple Resolutions

Usually using CSS you would fix horizontal scrolling by setting the following meta tag in your HTML page.

Unfortunately this does not work within our app. But fortunately for us, there is a fix to this but does take a little extra work.

The Fix

To fix the issue, we are going to leveraging some code from the open source PhoneGap project. Specifically we are going to look at the BrowserMouseHelper and some of the code in there.

I decided for my purposes to use just some code and not the entire class. To implement the fix, open up MainPage.xaml.cs and within the MainPage.Browser_Loaded() method, add the following code

Essentially in this piece of code, we use VisualTreeHelper to help us get the System.Windows.Controls.Border object within the visual tree so we can wire up the ManipulationDelta and ManipulationCompleted events to disable any scrolling in the WebBrowser window. Run the app and test the code.

Vertical Scrolling Only

Sometimes depending on your circumstances, you are going to have to scroll vertically, but the fix above will not do that.  To accommodate vertical scrolling we will need to add a bit of code to the ManipulationCompleted event handler as follows

When you run the app you should be able to scroll vertically but not horizontally, again, not what we want in our app, but it’s something you may want in yours.

scroll-vertically

We are pretty much done the sample, so in the next post I’ll go through some final polishing of the app to get it ready for Windows Store certification.

 

 

 

Trackbacks and Pingbacks:

  1. XBoxReveal HTML5 Windows Phone Sample: Store Certification | Mark Arteaga - May 7, 2013

    […] XBoxReveal HTML5 Windows Phone Sample: WebBrowser Control […]

Leave a Reply