This blog post was authored by Chee Chen Tong, a Program Manager on the Windows Phone team.
Setting the WebBrowser background color
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.
Rendering WebBrowser control content onto a bitmap
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:
WebBrowser control Hold event not being raised
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.
Updated November 7, 2014 11:43 pm