Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to change the background color of the WebBrowser control before loading content?

I have a page that contains a WebBrowser control that is frequently updating content. I am using a black background, but the default color before loading content of the WebBrowser is white. I could change it by loading a small HTML string with the background set to black but there is still a period of time when the WebBrowser appears as white so there is a sort of a flickering effect happening.

My question is this: is there any way to change the color of the underlying control of the WebBrowser?

I have tried a few solutions such as hiding the WebBrowser until the content has been loaded but none of these feel very elegant and don't work all that well.

like image 423
johnhforrest Avatar asked Apr 09 '11 00:04

johnhforrest


2 Answers

I've figured out something that works in my case. It's not necessarily the most elegant but it gets the job done.

I set the default Opacity of the WebBrowser to 0. Then, I attach an event handler for the LoadCompleted event:

private void browser_Post_LoadCompleted(object sender, NavigationEventArgs e)
{
    browser_Post.Opacity = 1;
}

Now, before I load a new HTML page, I set the Opacity back to 0 so it hides the browser while the new HTML is being rendered so there is no flickering of backgrounds. When the HTML is finished loading the event will fire and the new HTML page will be shown as expected.

like image 108
johnhforrest Avatar answered Nov 04 '22 07:11

johnhforrest


I agree with johnforrest. Its much better to Set the default Opacity to 0 and Opacity mask to Black in the XAML code. After that in the LoadComplete event;

private void dataBrowser_LoadCompleted(object sender,NavigationEventArgs e)
{
    dataBrowser.OpacityMask = null;
    dataBrowser.Opacity = 1;
}

No flickering...!!

like image 27
muj237 Avatar answered Nov 04 '22 06:11

muj237