Compartir a través de


CoreWebView2Controller.DefaultBackgroundColor Property

Definition

Gets or sets the WebView default background color.

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

Property Value

Examples

System.Drawing.Color backgroundColor = System.Drawing.Color.FromName(e.Parameter.ToString());
_iWebView2.DefaultBackgroundColor = backgroundColor;

Remarks

The `DefaultBackgroundColor` is the color that renders underneath all web content. This means WebView renders this color when there is no web content loaded such as before the initial navigation or between navigations. This also means web pages with undefined css background properties or background properties containing transparent pixels will render their contents over this color. Web pages with defined and opaque background properties that span the page will obscure the `DefaultBackgroundColor` and display normally. The default value for this property is white to resemble the native browser experience. Currently this API only supports opaque colors and transparency. It will fail for colors with alpha values that don't equal 0 or 255 ie. translucent colors are not supported. It also does not support transparency on Windows 7. On Windows 7, setting DefaultBackgroundColor to a Color with an Alpha value other than 255 will result in failure. On any OS above Win7, choosing a transparent color will result in showing hosting app content. This means webpages without explicit background properties defined will render web content over hosting app content. This property may also be set via the `WEBVIEW2_DEFAULT_BACKGROUND_COLOR` environment variable. There is a known issue with background color where just setting the color by property can still leave the app with a white flicker before the `DefaultBackgroundColor` property takes effect. Setting the color via environment variable solves this issue. The value must be a hex value that can optionally prepend a 0x. The value must account for the alpha value which is represented by the first 2 digits. So any hex value fewer than 8 digits will assume a prepended 00 to the hex value and result in a transparent color. `DefaultBackgroundColor` will return the result of this environment variable even if it has not been set directly. This environment variable can only set the `DefaultBackgroundColor` once. Subsequent updates to background color must be done by setting the property.

Applies to