@@ -30,20 +30,29 @@ applies the color too late.
30
30
wil::com_ptr<ICoreWebView2ControllerOptions> options;
31
31
HRESULT hr = m_environment->CreateCoreWebView2ControllerOptions(&options);
32
32
33
- wil::com_ptr<ICoreWebView2ControllerOptions> stagingOptions;
33
+ if (hr == E_INVALIDARG)
34
+ {
35
+ return S_OK;
36
+ }
37
+
38
+ wil::com_ptr<ICoreWebView2ControllerOptions> stagingOptions;wil::com_ptr<ICoreWebView2ControllerOptions4> options4;
34
39
auto result = options->QueryInterface(IID_PPV_ARGS(&stagingOptions));
35
40
41
+
42
+
36
43
if (SUCCEEDED(result))
37
44
{
38
45
COREWEBVIEW2_COLOR wvColor{255, 223, 225, 225};
39
46
stagingOptions->put_DefaultBackgroundColor(wvColor);
40
-
41
- m_environment->CreateCoreWebView2Controller(
42
- m_mainWindow, options.Get(),
43
- Callback<ICoreWebView2CreateCoreWebView2ControllerCompletedHandler>(
44
- this, &AppWindow::OnCreateCoreWebView2ControllerCompleted).Get());
45
47
}
46
48
49
+ m_environment->CreateCoreWebView2Controller(
50
+ m_mainWindow, options.Get(),
51
+ Callback<ICoreWebView2CreateCoreWebView2ControllerCompletedHandler>(
52
+ this, &AppWindow::OnCreateCoreWebView2ControllerCompleted).Get());
53
+
54
+ return S_OK;
55
+
47
56
}
48
57
```
49
58
@@ -59,9 +68,10 @@ SetDefaultBackgroundColor();
59
68
60
69
private void SetDefaultBackgroundColor ()
61
70
{
62
- CoreWebView2ControllerOptions options = WebView2 .CoreWebView2 .Environment .CreateCoreWebView2ControllerOptions ();
71
+ CoreWebView2Environment environment = CoreWebView2Environment .CreateAsync ();
72
+ CoreWebView2ControllerOptions options = environment .CreateCoreWebView2ControllerOptions ();
63
73
options .DefaultBackgroundColor = Color .FromArgb (0 , 0 , 255 );
64
- WebView2 .CoreWebView2 . Environment . CreateCoreWebView2ControllerAsync ( parentHwnd , options );
74
+ WebView2 .EnsureCoreWebView2Async ( environment , options );
65
75
}
66
76
67
77
```
@@ -87,15 +97,14 @@ interface ICoreWebView2ControllerOptions4 : IUnknown {
87
97
///
88
98
/// The ` DefaultBackgroundColor ` is the color that renders underneath all web
89
99
/// 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.
100
+ /// content loaded. When no background color is defined in WebView2, it uses
101
+ /// the ` DefaultBackgroundColor ` property to render the background.
102
+ /// By default, this color is set to white.
103
+ ///
91
104
/// Currently this API only supports opaque colors and transparency. It will
92
105
/// 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.
106
+ /// colors are not supported. When WebView2 is set to have a transparent background,
107
+ /// it renders the content of the parent window behind it.
99
108
100
109
[ propget] HRESULT DefaultBackgroundColor([ out, retval] COREWEBVIEW2_COLOR* value);
101
110
[ propput] HRESULT DefaultBackgroundColor([ in] COREWEBVIEW2_COLOR value);
0 commit comments