Язык

CoreWebView2ControllerOptions.DefaultBackgroundColor Property

Definition

This property allows users to initialize the DefaultBackgroundColor early, preventing a white flash that can occur while WebView2 is loading when the background color is set to something other than white. With early initialization, the color remains consistent from the start. After initialization, DefaultBackgroundColor will return the value set using this API.

The DefaultBackgroundColor can be set via the WEBVIEW2_DEFAULT_BACKGROUND_COLOR environment variable, which will remain supported for cases where this solution is being used. It is encouraged to transition away from the environment variable and use this API solution to apply the property. It is important to highlight that when set, the environment variable overrides DefaultBackgroundColor and becomes the initial value of DefaultBackgroundColor.

The DefaultBackgroundColor is the color that renders underneath all web content. This means WebView2 renders this color when there is no web content loaded. When no background color is defined in WebView2, it uses the DefaultBackgroundColor property to render the background. By default, this color is set to white.

This API only supports opaque colors and full transparency. It will fail for colors with alpha values that don't equal 0 or 255. When WebView2 is set to be fully transparent, it does not render a background, allowing the content from windows behind it to be visible.

public System.Drawing.Color DefaultBackgroundColor { get; set; }
member this.DefaultBackgroundColor : System.Drawing.Color with get, set
Public Property DefaultBackgroundColor As Color

Property Value

Applies to