New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BlazorWebView/WebView2 Transparent background not transparent on Windows #14185
Comments
This might be a limitation of the WebView2 control on WinUI, which is what .NET MAUI uses on Windows. We'll have to check. |
It also seems to work under WPF (which also uses the same WebView2 no?), e.g. as this StackOverflow post shows: |
Indeed, I recall the WPF issue, so I wonder if the same type of issue exists on WinUI as well. I found this issue, which seems to indicate that others have the same issue on WinUI: microsoft/microsoft-ui-xaml#6527 |
The other issue suggests that there could be a fairly easy workaround: microsoft/microsoft-ui-xaml#6527 (comment) So you could easily try that in an |
I inserted these lines in
But the result is still the same. I also tried inserting this in the constructor of |
Hmm then possibly the workaround just doesn't work? Because that's otherwise the same as what the others were saying in the WebView2 thread. |
At least on my machine ™ it doesn't. Edit: tried on another machine, doesnt work either |
Hmm yeah I don't see it working either in my test. |
We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process. |
Verified this issue with Visual Studio Enterprise 17.7.0 Preview 1.0. Can repro on windows platform with sample project. https://github.com/StonedHackerman/MauiBlazorWebViewTransparencyTest/tree/main/TransparencyTest. |
I'm not sure how they do it, but I thought the whole app (except maybe the title bar?) was a WebView, so maybe they don't even need to use transparency? Or also, perhaps it's hosted natively, which has somewhat different behaviors compared to how it's hosted on WindowsAppSDK (WinUI) and WPF/WinForms. |
Have there been any updates regarding this issue |
|
Any news on this? |
This Solution seems to work, create a new control that inherits the base class BlazorWebView, and then based on platform(when on windows) add init event. Add the below code and the issue seems to go away. private async void BlazorWebView_BlazorWebViewInitialized(object? sender, Microsoft.AspNetCore.Components.WebView.BlazorWebViewInitializedEventArgs e) |
@shyqrirama Unfortanetly the solution doesn't work for me. Can you maybe provide a minimal working example of your solution? |
Closing as this is not something we control: microsoft/microsoft-ui-xaml#6527 |
Description
What I did
I created a project from the default template ".NET MAUI Blazor App". In the MainPage I created a Label and a BlazorWebView which I shifted up a bit, so that it partly convers the Label. Then, I did these steps to make sure the page displayed in the BlazorWebView has transparent background:
MainPage.xaml
Index.razor
index.html
Result on Android (correct expected behavior)
On Android, I can correctly see the text in the P element on the Razor page inside a BlazorWebView overlayed on top of the MAUI Label
Result on Windows (incorrect behavior)
On Windows, the background is not transparent
The color displayed must be somehow related to the current Windows theme, because when I change my Windows theme from Dark to Light, the BlazorWebView's background color changes too
According to this link to Microsoft's official documentation, setting a WebView2's DefaultBackgroundColor to transparent is supported:
https://learn.microsoft.com/en-us/dotnet/api/microsoft.web.webview2.core.corewebview2controller.defaultbackgroundcolor?view=webview2-dotnet-1.0.864.35#microsoft-web-webview2-core-corewebview2controller-defaultbackgroundcolor
Which leads a logical conclusion that this is a bug, and the background should be transparent, like on Android.
Platforms/versions
I'm using VS Community 2022 v17.5.3 and the latest MAUI workload
The project contains these
TargetFrameworks
: (just the defaults from the template)This is the output from
dotnet workload list
Steps to Reproduce
Link to public reproduction project repository
https://github.com/StonedHackerman/MauiBlazorWebViewTransparencyTest/tree/main/TransparencyTest
Version with bug
7.0 (current)
Last version that worked well
Unknown/Other
Affected platforms
Windows
Affected platform versions
net7.0-windows10.0.19041.0
Did you find any workaround?
No, nothing I tried worked and no amount of Googling helped
Relevant log output
No response
The text was updated successfully, but these errors were encountered: