diff --git a/specs/CoreWebView2ControllerOptions.DefaultBackgroundColor.md b/specs/CoreWebView2ControllerOptions.DefaultBackgroundColor.md index 00fa26d5..4a5ef4b7 100644 --- a/specs/CoreWebView2ControllerOptions.DefaultBackgroundColor.md +++ b/specs/CoreWebView2ControllerOptions.DefaultBackgroundColor.md @@ -27,23 +27,31 @@ applies the color too late. ```cpp  HRESULT AppWindow::CreateControllerWithOptions() { - wil::com_ptr options; + wil::com_ptr options4; HRESULT hr = m_environment->CreateCoreWebView2ControllerOptions(&options); - wil::com_ptr stagingOptions; + if (hr == E_INVALIDARG) + { + return S_OK; + } + + wil::com_ptr options4; auto result = options->QueryInterface(IID_PPV_ARGS(&stagingOptions)); if (SUCCEEDED(result)) { COREWEBVIEW2_COLOR wvColor{255, 223, 225, 225}; stagingOptions->put_DefaultBackgroundColor(wvColor); - - m_environment->CreateCoreWebView2Controller( - m_mainWindow, options.Get(), - Callback( - this, &AppWindow::OnCreateCoreWebView2ControllerCompleted).Get()); } + m_environment->CreateCoreWebView2Controller( + m_mainWindow, + SUCCEEDED(result) ? stagingOptions.Get() : options.Get(), + Callback( + this, &AppWindow::OnCreateCoreWebView2ControllerCompleted).Get()); + + return S_OK; + } ``` @@ -53,15 +61,16 @@ applies the color too late. ```c# public MainWindow() { -InitializeComponent(); -SetDefaultBackgroundColor(); + InitializeComponent(); + SetDefaultBackgroundColor(); } private void SetDefaultBackgroundColor() { - CoreWebView2ControllerOptions options = WebView2.CoreWebView2.Environment.CreateCoreWebView2ControllerOptions(); + CoreWebView2Environment environment = CoreWebView2Environment.CreateAsync(); + CoreWebView2ControllerOptions options = environment.CreateCoreWebView2ControllerOptions(); options.DefaultBackgroundColor = Color.FromArgb(0, 0, 255); - WebView2.CoreWebView2.Environment.CreateCoreWebView2ControllerAsync(parentHwnd, options); + WebView2.EnsureCoreWebView2Async(environment, options); } ``` @@ -87,15 +96,14 @@ interface ICoreWebView2ControllerOptions4 : IUnknown { /// /// The `DefaultBackgroundColor` is the color that renders underneath all web /// content. This means WebView renders this color when there is no web - /// content loaded. It is important to note that the default color is white. + /// 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. + /// /// 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. + /// colors are not supported. When WebView2 is set to have a transparent background, + /// it renders the content of the parent window behind it. [propget] HRESULT DefaultBackgroundColor([out, retval] COREWEBVIEW2_COLOR* value); [propput] HRESULT DefaultBackgroundColor([in] COREWEBVIEW2_COLOR value);