3

On C#, how to use transparency in Webview2? Is it possible?

Does it work in WebBrowser but not WebView2?

Comparison

Broots Waymb
  • 4,713
  • 3
  • 28
  • 51
BenGost
  • 71
  • 1
  • 4

1 Answers1

8

You can change the WebView2.DefaultBackgroundColor (which defaults to white) to transparent to have a transparent background:

webView2.DefaultBackgroundColor = System.Drawing.Color.Transparent;

The WebView2 WPF sample app demonstrates this feature. WebView2 WPF sample app with a transparent background set for the WebView2

David Risney
  • 3,886
  • 15
  • 16
  • On UWP with WInUI 3 it shows the WebView does not contain any definition for DefaultBackgroundColor. Any idea about that? – Pratik Sep 25 '21 at 08:54