This blog post was authored by Chee Chen Tong, a Program Manager on the Windows Phone team.
You might want the background of the web content in your app to match your app’s overall design, or even match the theme the app user has set for their phone. Unfortunately, no matter what color you set for the WebBrowser control background, the user will see a flash of white background while the control initializes, and before the web content is loaded. This is because the WebBrowser control loads a white about:blank page during initialization, before any navigation occurs. Although Windows Phone 8 supports the DefaultBackground color property, the effective way to use this property depends on a certain sequence of events. You need to set the visibility of the WebBrowser control after the content has been navigated to or after the content has loaded. This code example illustrates how to do this:
While content is loading, and because the WebBrowser control itself is not yet visible, we recommend that you provide a visual progress indicator for the app user, either using the ProgressBar control, or with a spinner UI, for example.
Sharing is becoming a normal activity on the phone, and many app developers prefer to capture screenshots to use in sharing scenarios. On a typical page, you can use WriteableBitmap and pass it the LayoutRoot of a page to capture a screenshot of the page. In earlier releases of Windows Phone, if a WebBrowser control was embedded in the page, a blank rectangle displayed where the WebBrowser control was on the page. In Windows Phone 8, though, you can capture the content of a WebBrowser control with a few lines of code:
One of the things an app developer commonly would want to do is handle certain gesture events that aren’t supported by the WebBrowser control itself. The WebBrowser control doesn’t bubble up events, so you don’t have a reliable way to execute custom logic in response to specific user input.
One of these types of events is the Hold event. The WebBrowser control doesn’t provide a context menu for the Hold event, and the event is being consumed by the container control that hosts the WebBrowser control. If you followed the visual tree to get the container control, registering for the Hold event will work. The following code example shows you how to handle the Hold event, and to provide a context menu if you need to:
Be sure to see Mark Hopkins's blog post about hybrid web apps titled Make your mobile website into a Windows Phone app. For more information about Windows Phone web development, see Web development for Windows Phone.
thanks for this article.
I want some help of you .I want that my browser it self adjust its own height. what I know that its a must to give a height or its a zero by default.
My requirement is such that I can find height of html at run time content. I have tried through script by script notify I assign that height to browser. I don't getting success in that .
thanks in advance
What is this? My comment is cut in the middle before a less-than sign. And I can't edit it? And this happens on an official Microsoft website? Ohoh...
Adam, thanks for this article!
I tried the webbrowser hold Event (in WP8), but with the code above "Container" is always null.
var border0 = VisualTreeHelper.GetChild((WebBrowser)sender, 0);
var border1 = VisualTreeHelper.GetChild(border0, 0);
var interopCanvas = VisualTreeHelper.GetChild(border1, 0); // - do you know what this is?
var panZoom = VisualTreeHelper.GetChild(interopCanvas, 0);
var grid = VisualTreeHelper.GetChild(panZoom, 0);
var Container = VisualTreeHelper.GetChild(grid, 0) as Border;
But more important, is it possible to get details of the web page element, that is touched? For example a link or a picture url? The usual InvokeScript method is poor...
var interopCanvas = VisualTreeHelper.GetChild(border1, 0); //