question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

WebView2.DefaultBackgroundColor cannot be set to a transparent background

See original GitHub issue

Describe the bug

Setting WebView2.DefaultBackgroundColor to transparent results in a Background that seems to be equivalent to the color of ApplicationPageBackgroundThemeBrush (e.g. 32, 32, 32 in Dark theme). That is not what I want. And changing the RequestedTheme at runtime after CoreWebView2 has initialized has no effect on the background color. Moreover, changing the RequestedTheme has no effect at all, the WebView2 control seems to set the background based on the ApplicationTheme which cannot be changed at runtime.

Steps to reproduce the bug

XAML:

<Grid Background="Red">
  <WebView2 DefaultBackgroundColor="Transparent" Loading="WebView2loading"></WebView2>
</Grid>

C#:

private async void WebView2loading(FrameworkElement sender, object args)
{
  await ((WebView2)sender).EnsureCoreWebView2Async();
}

Expected behavior

The expected behavior is that setting the BackgroundColor to transparent should set the background color to transparent.

Screenshots

Screenshot 2021-12-29 152317 The Background should be red in the example.

NuGet package version

WinUI 3 - Windows App SDK 1.0 (If you’re seeing your issue in older previews of WinUI 3, please try this release)

Windows app type

  • UWP
  • Win32

Device form factor

Desktop

Windows version

Insider Build (xxxxx)

Additional context

Testet on 21H2 (22000.376)

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:2
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
agennecommented, Mar 7, 2023

The target version of our UWP App is 19041

Note that there is another issue: https://github.com/MicrosoftEdge/WebView2Feedback/issues/2917

Because of this one we can’t go live for months

2reactions
DexterLeungcommented, Jun 16, 2022

The issue still exists in WinUI 3 ver 1.1 C# Desktop

Read more comments on GitHub >

github_iconTop Results From Across the Web

WebView DefaultBackgroundColor Transparent does not ...
If WebView.DefaultBackgroundColor is Transparent, it means that the WebView itself has no background, but the background color is provided ...
Read more >
WebView DefaultBackgroundColor Transparent ...
I am attempting to draw a WebView element that has DefaultBackgroundColor set to transparent (no html background is set) to a WebViewBrush.
Read more >
CoreWebView2Controller.DefaultBackgroundColor Property
On any OS above Win7, choosing a transparent color will result in showing hosting app content. This means webpages without explicit background properties...
Read more >
[Solved]-How to use transparency in Webview2?-C#
You can change the WebView2.DefaultBackgroundColor (which defaults to white) to transparent to have a transparent background: webView2.
Read more >
WebView2 - Page 6 - AutoHotkey Community
The format of DefaultBackgroundColor is BGRA. ... However, changing FF to 00, which is *supposed* to make the background transparent, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found