I did a search to find out how to change my browser control background. I’m using the Windows Phone 8 SDK and the WebBrowser control.

The reference that I found on this subject seemed to be related to the flicker that shows up when the page is displayed with this control. I think that this was limited to phones using the dark theme. Overall, the flicker or flash that happens for a moment is only a minor problem for me. My problem was more a problem with the content that gets displayed in the control.

My content is a privacy policy HTML file. The file is content that is distributed with the app, so I have full control over it. What I really wanted was to display this white-on-black for a dark theme and black-on-white for a light theme. Getting rid of any flash or flicker is a bonus.

The Solution

  1. Add CSS style information to the HTML file to hold a background color and a foreground color.
  2. Change these values at runtime.

That’s it. Here’s some code snippets…

The XAML is shown because there is an opacity attribute that is important for removing the flicker of a color change. I only included the important part of the privacy policy HTML file. This is the part that has the colors in it. And finally, the C# file contains a few different functions for changing the color and displaying the file. Note the dispatch call to change the opacity in the UI thread. This reduced the flicker to zero, whereas changing it right where that dispatch is called would still result in some flashing.

Of course, none of this is very useful for pages that are not local. The flickering can be reduced with the opacity change, but color changes would be complicated without complete control over the HTML file.