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.
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.
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...!!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With