|
| 1 | +Custom ScrollBar Style |
| 2 | +=== |
| 3 | + |
| 4 | +# Background |
| 5 | +Developers would like to be able to set the ScrollBar to Windows fluent overlay style and |
| 6 | +match the Windows theme. Some customers have used browser flags but they change names and behavior and are not reliable. Thus we want |
| 7 | +to provide an extendable API that allows developers to set ScrollBar style. Currently, |
| 8 | +only Windows fluent overlay are supported, adding new styles in the future will not introduce |
| 9 | +any breaking changes. |
| 10 | + |
| 11 | +# Examples |
| 12 | +## WinRT and .NET |
| 13 | +```c# |
| 14 | +// Create WebView Environment with option |
| 15 | +async void CreateEnvironmentWithOption() |
| 16 | +{ |
| 17 | + CoreWebView2EnvironmentOptions options = new CoreWebView2EnvironmentOptions(); |
| 18 | + options.ScrollBarStyle = ScrollBarStyle.FluentOverlay; |
| 19 | + CoreWebView2Environment environment = await CoreWebView2Environment.CreateAsync(options: options); |
| 20 | + webview.EnsureCoreWebView2Async(environment); |
| 21 | +} |
| 22 | +``` |
| 23 | + |
| 24 | +## Win32 C++ |
| 25 | +```cpp |
| 26 | +void AppWindow::InitializeWebView() |
| 27 | +{ |
| 28 | + auto options = Microsoft::WRL::Make<CoreWebView2EnvironmentOptions>(); |
| 29 | + COREWEBVIEW2_SCROLLBAR_STYLE style = COREWEBVIEW2_SCROLLBAR_STYLE_FLUENT_OVERLAY; |
| 30 | + CHECK_FAILURE(options->put_ScrollBarStyle(style)); |
| 31 | + |
| 32 | + // ... other option properties |
| 33 | + |
| 34 | + // ... CreateCoreWebView2EnvironmentWithOptions |
| 35 | +} |
| 36 | +``` |
| 37 | + |
| 38 | +# API Notes |
| 39 | + |
| 40 | +See [API Details](#api-details) section below for API reference. |
| 41 | + |
| 42 | +# API Details |
| 43 | +## Win32 C++ |
| 44 | + |
| 45 | +```IDL |
| 46 | +interface ICoreWebView2EnvironmentOptions7; |
| 47 | +
|
| 48 | +[v1_enum] |
| 49 | +typedef enum COREWEBVIEW2_SCROLLBAR_STYLE { |
| 50 | + /// Browser default ScrollBar style |
| 51 | + COREWEBVIEW2_SCROLLBAR_STYLE_DEFAULT, |
| 52 | + /// Window style fluent overlay scroll bar |
| 53 | + /// Please see [Fluent UI](https://developer.microsoft.com/en-us/fluentui#/) |
| 54 | + /// for more details on fluent UI. |
| 55 | + COREWEBVIEW2_SCROLLBAR_STYLE_FLUENT_OVERLAY |
| 56 | +} COREWEBVIEW2_SCROLLBAR_STYLE; |
| 57 | +
|
| 58 | +/// Additional options used to create WebView2 Environment. |
| 59 | +[uuid(9c8ac95a-6b5f-4efb-b5f6-98bb33469759), object, pointer_default(unique)] |
| 60 | +interface ICoreWebView2EnvironmentOptions7 : ICoreWebView2EnvironmentOptions6 { |
| 61 | + /// Get the ScrollBar style being set on the WebView2 Environment. |
| 62 | + [propget] HRESULT ScrollBarStyle([out, retval] COREWEBVIEW2_SCROLLBAR_STYLE* value); |
| 63 | + /// Set ScrollBar style to be used. The default is `COREWEBVIEW2_SCROLLBAR_STYLE_DEFAULT` |
| 64 | + /// which specifies the default browser ScrollBar style. |
| 65 | + /// CSS styles that modify the ScrollBar applied on top of native ScrollBar styling |
| 66 | + /// that is selected with `ScrollBarStyle`. |
| 67 | + [propput] HRESULT ScrollBarStyle([in] COREWEBVIEW2_SCROLLBAR_STYLE value); |
| 68 | +} |
| 69 | +``` |
| 70 | + |
| 71 | +## .NET and WinRT |
| 72 | + |
| 73 | +```c# |
| 74 | +namespace Microsoft.Web.WebView2.Core |
| 75 | +{ |
| 76 | + |
| 77 | + enum ScrollBarStyle |
| 78 | + { |
| 79 | + Default = 0, |
| 80 | + FluentOverlay = 1, |
| 81 | + }; |
| 82 | + |
| 83 | + // ... |
| 84 | + runtimeclass CoreWebView2EnvironmentOptions |
| 85 | + { |
| 86 | + [interface_name("Microsoft.Web.WebView2.Core.ICoreWebView2EnvironmentOptions7")] |
| 87 | + { |
| 88 | + // Set ScrollBar style |
| 89 | + ScrollBarStyle ScrollBarStyle { get; set; }; |
| 90 | + } |
| 91 | + } |
| 92 | + |
| 93 | + // ... |
| 94 | +} |
| 95 | +``` |
0 commit comments