@@ -27,23 +27,31 @@ applies the color too late.
2727``` cpp
2828 HRESULT AppWindow::CreateControllerWithOptions ()
2929{
30- wil::com_ptr<ICoreWebView2ControllerOptions> options ;
30+ wil::com_ptr<ICoreWebView2ControllerOptions4> options4 ;
3131 HRESULT hr = m_environment->CreateCoreWebView2ControllerOptions(&options);
3232
33- wil::com_ptr<ICoreWebView2ControllerOptions> stagingOptions;
33+ if (hr == E_INVALIDARG)
34+ {
35+ return S_OK;
36+ }
37+
38+ wil::com_ptr<ICoreWebView2ControllerOptions4> options4;
3439 auto result = options->QueryInterface(IID_PPV_ARGS(&stagingOptions));
3540
3641 if (SUCCEEDED(result))
3742 {
3843 COREWEBVIEW2_COLOR wvColor{255, 223, 225, 225};
3944 stagingOptions->put_DefaultBackgroundColor(wvColor);
40-
41- m_environment->CreateCoreWebView2Controller(
42- m_mainWindow, options.Get(),
43- Callback<ICoreWebView2CreateCoreWebView2ControllerCompletedHandler>(
44- this, &AppWindow::OnCreateCoreWebView2ControllerCompleted).Get());
4545 }
4646
47+ m_environment->CreateCoreWebView2Controller(
48+ m_mainWindow,
49+ SUCCEEDED (result) ? stagingOptions.Get() : options.Get(),
50+ Callback<ICoreWebView2CreateCoreWebView2ControllerCompletedHandler >(
51+ this, &AppWindow::OnCreateCoreWebView2ControllerCompleted).Get());
52+
53+ return S_OK;
54+
4755}
4856```
4957
@@ -53,15 +61,16 @@ applies the color too late.
5361``` c#
5462public MainWindow ()
5563{
56- InitializeComponent ();
57- SetDefaultBackgroundColor ();
64+ InitializeComponent ();
65+ SetDefaultBackgroundColor ();
5866}
5967
6068private void SetDefaultBackgroundColor ()
6169{
62- CoreWebView2ControllerOptions options = WebView2 .CoreWebView2 .Environment .CreateCoreWebView2ControllerOptions ();
70+ CoreWebView2Environment environment = CoreWebView2Environment .CreateAsync ();
71+ CoreWebView2ControllerOptions options = environment .CreateCoreWebView2ControllerOptions ();
6372 options .DefaultBackgroundColor = Color .FromArgb (0 , 0 , 255 );
64- WebView2 .CoreWebView2 . Environment . CreateCoreWebView2ControllerAsync ( parentHwnd , options );
73+ WebView2 .EnsureCoreWebView2Async ( environment , options );
6574}
6675
6776```
@@ -87,15 +96,14 @@ interface ICoreWebView2ControllerOptions4 : IUnknown {
8796 ///
8897 /// The ` DefaultBackgroundColor ` is the color that renders underneath all web
8998 /// content. This means WebView renders this color when there is no web
90- /// content loaded. It is important to note that the default color is white.
99+ /// content loaded. When no background color is defined in WebView2, it uses
100+ /// the ` DefaultBackgroundColor ` property to render the background.
101+ /// By default, this color is set to white.
102+ ///
91103 /// Currently this API only supports opaque colors and transparency. It will
92104 /// fail for colors with alpha values that don't equal 0 or 255 ie. translucent
93- /// colors are not supported. It also does not support transparency on Windows 7.
94- /// On Windows 7, setting DefaultBackgroundColor to a Color with an Alpha value
95- /// other than 255 will result in failure. On any OS above Win7, choosing a
96- /// transparent color will result in showing hosting app content. This means
97- /// webpages without explicit background properties defined will render web
98- /// content over hosting app content.
105+ /// colors are not supported. When WebView2 is set to have a transparent background,
106+ /// it renders the content of the parent window behind it.
99107
100108 [ propget] HRESULT DefaultBackgroundColor([ out, retval] COREWEBVIEW2_COLOR* value);
101109 [ propput] HRESULT DefaultBackgroundColor([ in] COREWEBVIEW2_COLOR value);
0 commit comments