@@ -47,7 +47,7 @@ applies the color too late.
47
47
48
48
m_environment->CreateCoreWebView2ControllerWithOptions(
49
49
m_mainWindow,
50
- SUCCEEDED (result) ? options4.Get() : options.Get(),
50
+ options.Get(),
51
51
Callback<ICoreWebView2CreateCoreWebView2ControllerCompletedHandler>(
52
52
this, &AppWindow::OnCreateCoreWebView2ControllerCompleted).Get());
53
53
@@ -66,12 +66,14 @@ public MainWindow()
66
66
SetDefaultBackgroundColor ();
67
67
}
68
68
69
- private void SetDefaultBackgroundColor ()
69
+ private async Task
70
+ SetDefaultBackgroundColor ()
70
71
{
71
- CoreWebView2Environment environment = CoreWebView2Environment .CreateAsync ();
72
+ CoreWebView2Environment environment = await
73
+ CoreWebView2Environment .CreateAsync ();
72
74
CoreWebView2ControllerOptions options = environment .CreateCoreWebView2ControllerOptions ();
73
75
options .DefaultBackgroundColor = Color .FromArgb (255 , 85 , 0 , 255 );
74
- WebView2 .EnsureCoreWebView2Async (environment , options );
76
+ await WebView2 .EnsureCoreWebView2Async (environment , options );
75
77
}
76
78
77
79
```
@@ -82,29 +84,30 @@ private void SetDefaultBackgroundColor()
82
84
83
85
## Win32 C++
84
86
``` cpp
85
- // / This interface extends the ICoreWebView2ControllerOptions interface to expose the DefaultBackgroundColor property.
86
- // / It is encouraged to transition away from the environment variable and use this API solution to apply the property.
87
+ // / This interface extends the ICoreWebView2ControllerOptions interface to expose
88
+ // / DefaultBackgroundColor property. It is encouraged to transition away from the
89
+ // / environment variable and use this API solution to apply the property.
87
90
88
91
[uuid(df9cb70b-8d87-5bca-ae4b-6f23285e8d94), object, pointer_default(unique)]
89
92
interface ICoreWebView2ControllerOptions4 : ICoreWebView2ControllerOptions3 {
90
93
91
94
/// This API allows users to initialize the ` DefaultBackgroundColor ` early,
92
- /// preventing a white flash that can happen while WebView2 is loading when
95
+ /// preventing a white flash that can occur while WebView2 is loading when
93
96
/// the background color is set to something other than white. With early
94
97
/// initialization, the color remains consistent from the start. After
95
98
/// initialization, ` ICoreWebView2Controller2::get_DefaultBackgroundColor `
96
- /// will return the value set using this API.
99
+ /// will return the value set using this API.
97
100
///
98
101
/// The ` DefaultBackgroundColor ` is the color that renders underneath all web
99
102
/// content. This means WebView renders this color when there is no web
100
103
/// content loaded. When no background color is defined in WebView2, it uses
101
104
/// the ` DefaultBackgroundColor ` property to render the background.
102
105
/// By default, this color is set to white.
103
106
///
104
- /// Currently this API only supports opaque colors and transparency. It will
105
- /// fail for colors with alpha values that don't equal 0 or 255 ie. translucent
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.
107
+ /// This API only supports opaque colors and full transparency. It will
108
+ /// fail for colors with alpha values that don't equal 0 or 255.
109
+ /// When WebView2 is set to be fully transparent, it does not render a background,
110
+ /// allowing the content from windows behind it to be visible .
108
111
109
112
[ propget] HRESULT DefaultBackgroundColor([ out, retval] COREWEBVIEW2_COLOR* value);
110
113
[ propput] HRESULT DefaultBackgroundColor([ in] COREWEBVIEW2_COLOR value);
0 commit comments