TwokaB icon indicating copy to clipboard operation
TwokaB copied to clipboard

[Question] - How do I get rid of the white background of the BlazorWebview during load?

Open geocine opened this issue 3 years ago • 9 comments

See this demo below, to understand behavior while window is opening

  • gray -> window load
  • white -> BlazorWebView loading
  • pink -> index.html load

webview

I tried adding "Aqua" Background to the BlazorWebView but still the White view is showing

  • aqua-> BlazorWebview init
  • white -> BlazorWebView loading
  • pink -> index.html load

webview2

geocine avatar Oct 29 '21 11:10 geocine

Pretty sure the white background is the browser window, before the blazor HTML is loaded. As I don't actively maintain this codebase anymore and MBB and .net 6 are the spiritual successors to TwokaB, I'd say the easiest solution is either to overlay or hide the control until everything is loaded, or adapt the code to try and set this background colour of the embedded browser window.

jspuij avatar Oct 30 '21 07:10 jspuij

For the second image you can see I already set the BlazorWevbiew "Background" property to "aqua" but still a white background is showing after that "aqua" background which I have set.

FYI I forgot the exact syntax and I'm not infront of the PC rn, but ii already looks something like this

<BlazorWebview Background="aqua" />

Then the "pink" color is coming from the "index.html" page

<style>
body {
  background: "pink"; 
}
</style>

geocine avatar Oct 30 '21 07:10 geocine

@geocine did you end up finding a solution for this?

adds39939 avatar Jun 17 '22 17:06 adds39939

I am interested too.

It doesn't work even after changing the BlazorWebView bg and style colors.

SqueakyBed avatar Oct 02 '22 23:10 SqueakyBed

I still don't have a solution unfortunately

geocine avatar Nov 04 '22 18:11 geocine

Any findings yet?

KrystianLesniak avatar Apr 18 '23 11:04 KrystianLesniak

My solution.

    ViewHandler.ViewMapper.AppendToMapping(nameof(IView.Background), (handler, view) =>
    {
        if (handler.PlatformView is WebView2 wv)
        {
            //Change the background of the web browser to the current theme color to prevent unwanted flashing when refreshing the page. 
            wv.DefaultBackgroundColor = Windows.UI.Color.FromArgb(Alpha, Red, Green, Blue);
        }
    });

SqueakyBed avatar Sep 03 '23 06:09 SqueakyBed

Have there been any updates regarding this issue

SimenCTan avatar Oct 26 '23 03:10 SimenCTan

To resolve the issue on macOS

  public static void ModifyBlazorWebView() 
  {
      ViewHandler.ViewMapper.AppendToMapping(nameof(IView.Background), (handler, view) =>
      {
#if MACCATALYST || IOS
          if (handler.PlatformView is WKWebView wv)
          {
              wv.Opaque = false;
              wv.BackgroundColor = UIColor.Clear;
          }
#endif
      });
  }

SimenCTan avatar Oct 27 '23 03:10 SimenCTan