Skip to content

Commit 47d56b5

Browse files
committed
add WinForms plat article
1 parent 7a0b4e3 commit 47d56b5

9 files changed

Lines changed: 110 additions & 42 deletions

File tree

microsoft-edge/toc.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,8 +1347,8 @@
13471347

13481348
- name: WinForms
13491349
items:
1350-
# - name: WebView2 in WinForms apps
1351-
# href: ./webview2/platforms/winforms.md
1350+
- name: WebView2 in WinForms apps
1351+
href: ./webview2/platforms/winforms.md
13521352

13531353
- name: WinForms sample app
13541354
href: ./webview2/samples/webview2windowsformsbrowser.md

microsoft-edge/webview2/get-started/hololens2.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,6 @@ public class WebViewExample : MonoBehaviour, IWithPostMessage
409409
```
410410

411411

412-
413412
<!-- ====================================================================== -->
414413
## See also
415414

microsoft-edge/webview2/get-started/winui2.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ Only a subset of WebView2 interfaces/functions are exposed in WinUI:
6161

6262
* Interfaces such as `CoreWebView2Controller` are hidden, because WinUI takes care of the environment and window creation behind the scenes.
6363

64-
See also [XAML limitation](#xaml-limitation) below.
64+
See also:
65+
* [XAML limitation](../platforms/winui2-uwp.md#xaml-limitation) in _WebView2 in WinUI 2 (UWP) apps_.
6566

6667

6768
<!-- ====================================================================== -->
@@ -299,16 +300,19 @@ Next, learn about navigation events, which are essential for WebView2 apps. The
299300
<!-- ====================================================================== -->
300301
## See also
301302

303+
* [WebView2 in WinUI 2 (UWP) apps](../platforms/winui2-uwp.md)
302304
* [WebView2 API Reference](../webview2-api-reference.md)
303-
* [WinUI 2 (UWP) sample app](../samples/webview2_sample_uwp.md) - steps to download, update, build, and run the WinUI 2 WebView2 sample.
304-
* [Manage user data folders](../concepts/user-data-folder.md)
305-
* [WebView2 sample apps](../code-samples-links.md) - a guide to the `WebView2Samples` repo.
306305
* [Development best practices for WebView2 apps](../concepts/developer-guide.md)
306+
* [Manage user data folders](../concepts/user-data-folder.md)
307+
* [WebView2 sample apps](../code-samples-links.md) - a guide to the `WebView2Samples` repo.
308+
* [WinUI 2 (UWP) sample app](../samples/webview2_sample_uwp.md) - steps to download, update, build, and run the WinUI 2 WebView2 sample.
309+
* Get Started tutorial finished project: Unlike some of the other tutorials, there isn't a completed version of this Getting Started tutorial in the WebView2Samples repo.
307310

308311
GitHub:
309312
* [WebView2Samples repo](https://github.com/MicrosoftEdge/WebView2Samples)
310313
* [WebView2 UWP Sample App](https://github.com/MicrosoftEdge/WebView2Samples/tree/main/SampleApps/webview2_sample_uwp) - the WinUI 2 (UWP) WebView2 sample.
311314
* [Issues - microsoft-ui-xaml repo](https://github.com/microsoft/microsoft-ui-xaml/issues) - to enter WinUI-specific feature requests or bugs.
312-
* Unlike some of the other tutorials, there isn't a completed version of this Getting Started tutorial in the WebView2Samples repo.
313-
* [Microsoft.UI.Xaml NuGet package](https://www.nuget.org/packages/Microsoft.UI.Xaml/)
314315
* [Media App Samples for Xbox](https://github.com/microsoft/Media-App-Samples-for-Xbox)
316+
317+
NuGet:
318+
* [Microsoft.UI.Xaml NuGet package](https://www.nuget.org/packages/Microsoft.UI.Xaml/)

microsoft-edge/webview2/platforms/hololens-2-unity.md

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ This article is for developers using WebView2 in immersive HoloLens 2 Unity appl
1717
1818
WebView2 on HoloLens 2 and the WebView plugin for Unity are both in Preview and are subject to change before general availability.
1919

20-
WebView2 only works on HoloLens 2 devices running the Windows 11 update. For more information, see [Update HoloLens 2](/hololens/hololens-update-hololens).
20+
WebView2 only works on HoloLens 2 devices running the Windows 11 update. For more information, see [Update HoloLens 2](/hololens/hololens-update-hololens).
2121

22-
For WebView2-enabled 2D applications on HoloLens 2, see [Get started with WebView2 in WinUI 2 (UWP) apps](./winui2.md).
22+
For WebView2-enabled 2D applications on HoloLens 2, see [Get started with WebView2 in WinUI 2 (UWP) apps](../get-started/winui2.md).
2323

2424

2525
<!-- ====================================================================== -->
@@ -31,25 +31,25 @@ For WebView2-enabled 2D applications on HoloLens 2, see [Get started with WebVie
3131

3232
When developing a HoloLens 2 Unity app with WebView2, be aware of some limitations and known issues:
3333

34-
* **Pop-ups**: Pop-ups don't work well within WebView2 inside Unity apps on HoloLens 2, but they work fine in 2D XAML apps on the device. Avoid pop-ups and use alternative techniques or UI designs, such as custom pop-up-like elements within the WebView using HTML, CSS, and JavaScript.
34+
* **Pop-ups**: Pop-ups don't work well within WebView2 inside Unity apps on HoloLens 2, but they work fine in 2D XAML apps on the device. Avoid pop-ups and use alternative techniques or UI designs, such as custom pop-up-like elements within the WebView using HTML, CSS, and JavaScript.
3535

36-
* **New windows**: WebView2 instances on HoloLens 2 navigate within the same window by default, unlike on Desktop. Follow this default behavior for a better user experience. Additionally, the DevTools window cannot be launched.
36+
* **New windows**: WebView2 instances on HoloLens 2 navigate within the same window by default, unlike on Desktop. Follow this default behavior for a better user experience. Additionally, the DevTools window cannot be launched.
3737

38-
* **Enterprise authentication**: Automatic Single Sign-On (SSO) leveraging OS-level tokens is currently not supported in WebView2 on HoloLens 2. Users can still sign in by providing credentials, except for cases requiring device-level authentication. Cookie storage works as expected.
38+
* **Enterprise authentication**: Automatic Single Sign-On (SSO) leveraging OS-level tokens is currently not supported in WebView2 on HoloLens 2. Users can still sign in by providing credentials, except for cases requiring device-level authentication. Cookie storage works as expected.
3939

40-
* **User interactions**: Unlike native HoloLens 2 slates, WebView2 is best interacted with by using far-interaction hand rays. Touch-to-swipe and scroll interactions might not be supported.
40+
* **User interactions**: Unlike native HoloLens 2 slates, WebView2 is best interacted with by using far-interaction hand rays. Touch-to-swipe and scroll interactions might not be supported.
4141

42-
* **Performance**: Complex websites with heavy use of JavaScript or advanced rendering may impact system performance or the host application's framerate. For general performance-related limitations and recommendations, see [Understanding performance for mixed reality](/windows/mixed-reality/develop/advanced-concepts/understanding-performance-for-mixed-reality) in the mixed reality documentation. Also see [Performance optimization](#performance-optimization), below.
42+
* **Performance**: Complex websites with heavy use of JavaScript or advanced rendering may impact system performance or the host application's framerate. For general performance-related limitations and recommendations, see [Understanding performance for mixed reality](/windows/mixed-reality/develop/advanced-concepts/understanding-performance-for-mixed-reality) in the mixed reality documentation. Also see [Performance optimization](#performance-optimization), below.
4343

4444

4545
<!-- ------------------------------ -->
4646
#### Performance optimization
4747

48-
Optimizing the performance of WebView2 in your HoloLens 2 Unity app is crucial for a smooth user experience. Here are some recommendations:
48+
Optimizing the performance of WebView2 in your HoloLens 2 Unity app is crucial for a smooth user experience. Here are some recommendations:
4949

50-
* **Limit the number of WebView2 instances**: We suggest using only one instance of WebView2 within a Unity app. Reuse the same instance or tear down and create a new one as needed. Keep in mind that removing the WebView prefab from the scene might not destroy the underlying WebView2 instance. You must call the `Destroy()` method on the game object to destroy it properly.
50+
* **Limit the number of WebView2 instances**: We suggest using only one instance of WebView2 within a Unity app. Reuse the same instance or tear down and create a new one as needed. Keep in mind that removing the WebView prefab from the scene might not destroy the underlying WebView2 instance. You must call the `Destroy()` method on the game object to destroy it properly.
5151

52-
* **Apply general Unity optimization techniques**: To optimize WebView2 performance, use the standard Unity optimization approaches, such as occlusion culling or limiting the update rate. For more information, see [Performance recommendations for Unity](/windows/mixed-reality/develop/unity/performance-recommendations-for-unity?tabs=openxr) in the mixed reality documentation.
52+
* **Apply general Unity optimization techniques**: To optimize WebView2 performance, use the standard Unity optimization approaches, such as occlusion culling or limiting the update rate. For more information, see [Performance recommendations for Unity](/windows/mixed-reality/develop/unity/performance-recommendations-for-unity?tabs=openxr) in the mixed reality documentation.
5353

5454
* **Profile and monitor WebView2 performance**: There are several ways to profile the performance of a HoloLens 2 Unity application:
5555

@@ -63,21 +63,19 @@ Optimizing the performance of WebView2 in your HoloLens 2 Unity app is crucial f
6363
<!-- ------------------------------ -->
6464
#### Navigation
6565

66-
In [Step 7 - Extending WebView2 functionality](#step-7---extending-webview2-functionality), we touched on some navigation methods. In this section, we'll expand on what we learned.
66+
Some navigation methods are demonstrated in [Step 7 - Extending WebView2 functionality](../get-started/hololens2.md#step-7---extending-webview2-functionality) in _Get started with WebView2 in HoloLens 2 Unity apps (Preview)_. The present section expands on that demonstration.
6767

6868
See also:
6969
* [WebView2 API Reference](../webview2-api-reference.md)
70-
* [API Reference for Mixed Reality WebView plugin](/windows/mixed-reality/develop/advanced-concepts/webview2-unity-plugin) - for HoloLens 2 in the WebView2 Unity plugin.
71-
<!-- dest. TOC title:
72-
WebView2 Unity Plugin API -->
70+
* [API Reference for Mixed Reality WebView plugin](/windows/mixed-reality/develop/advanced-concepts/webview2-unity-plugin) - for HoloLens 2 in the WebView2 Unity plugin.<!-- toc title: WebView2 Unity Plugin API -->
7371

7472

7573
<!-- ---------- -->
7674
###### IWebView interface
7775

7876
<!-- [IWebView::Load method]()-->
7977

80-
The `IWebView` interface exposes a few methods, events, and properties related to page navigation. The main functionality exposed here is the ability to navigate to a given URL, by using `Load(Uri url)`:
78+
The `IWebView` interface exposes a few methods, events, and properties related to page navigation. The main functionality exposed here is the ability to navigate to a given URL, by using `Load(Uri url)`:
8179

8280
```C#
8381
public interface IWebView
@@ -98,7 +96,7 @@ public interface IWebView
9896
<!-- ---------- -->
9997
###### IWithBrowserHistory interface
10098

101-
The `IWithBrowserHistory` interface exposes a few methods and events related to page navigation. This mainly allows developers to navigate forward and backward, as you would expect with a typical web-browsing experience:
99+
The `IWithBrowserHistory` interface exposes a few methods and events related to page navigation. This mainly allows developers to navigate forward and backward, as you would expect with a typical web-browsing experience:
102100

103101
```C#
104102
public interface IWithBrowserHistory : IWebView
@@ -119,7 +117,7 @@ public interface IWithBrowserHistory : IWebView
119117
<!-- ---------- -->
120118
###### SetVirtualHostNameToFolderMapping and SetVirtualHostMapping
121119

122-
The [CoreWebView2.SetVirtualHostNameToFolderMapping Method](/dotnet/api/microsoft.web.webview2.core.corewebview2.setvirtualhostnametofoldermapping) enables mapping between a virtual host name and a folder path, making it accessible to websites using that host name. This method maps a local domain name to a local folder, so that the WebView2 control loads content from the specified local folder when attempting to access a resource for that domain.
120+
The [CoreWebView2.SetVirtualHostNameToFolderMapping Method](/dotnet/api/microsoft.web.webview2.core.corewebview2.setvirtualhostnametofoldermapping) enables mapping between a virtual host name and a folder path, making it accessible to websites using that host name. This method maps a local domain name to a local folder, so that the WebView2 control loads content from the specified local folder when attempting to access a resource for that domain.
123121

124122
The WebView plugin for Unity exposes this functionality through the `IWithVirtualHost` interface, which has a single method, `SetVirtualHostMapping(string hostName, string folderPath)`:
125123

@@ -130,7 +128,7 @@ public interface IWithVirtualHost : IWebView
130128
}
131129
```
132130

133-
To use the `SetVirtualHostMapping` method, set `hostName` to any valid URL conforming string, such as `webview2.sample`. `folderPath` can be an absolute path or a path relative to the application's working directory, such as `Assets\Html`.
131+
To use the `SetVirtualHostMapping` method, set `hostName` to any valid URL conforming string, such as `webview2.sample`. `folderPath` can be an absolute path or a path relative to the application's working directory, such as `Assets\Html`.
134132

135133
Assuming we have an HTML file called `demo.html` under `Assets\Html`, the following code snippet demonstrates loading `demo.html` by using the WebView plugin for Unity:
136134

@@ -164,7 +162,7 @@ There are various ways to handle input in Unity for mixed reality applications.
164162
* [Input — MRTK3](/windows/mixed-reality/mrtk-unity/mrtk3-input/packages/input/overview) - recommended for Mixed Reality Toolkit 3 applications.
165163
* [Unity Input System](https://docs.unity3d.com/Packages/com.unity.inputsystem@1.5/manual/index.html)
166164

167-
Regardless of the input system used within your Unity application, interop code between the various application input events and the WebView plugin for Unity is required. This means translating those events (such as Pointer events) into a `WebViewMouseEventData` object and then forwarding those events to the plugin via the `IWithMouseEvent` interface:
165+
Regardless of the input system used within your Unity application, interop code between the various application input events and the WebView plugin for Unity is required. This means translating those events (such as Pointer events) into a `WebViewMouseEventData` object and then forwarding those events to the plugin via the `IWithMouseEvent` interface:
168166

169167
```C#
170168
public interface IWithMouseEvents : IWithInputEvents
@@ -173,7 +171,7 @@ public interface IWithMouseEvents : IWithInputEvents
173171
}
174172
```
175173

176-
WebView2 is unaware of Unity's input system and likely has a different coordinate system than your Unity scene. As a result, when there is a pointer-down event, its coordinates must be translated into the coordinate system of the WebView2 control. Additionally, the pointer-down event needs to be converted into an appropriate `WebViewMouseEventData` event type.
174+
WebView2 is unaware of Unity's input system and likely has a different coordinate system than your Unity scene. As a result, when there is a pointer-down event, its coordinates must be translated into the coordinate system of the WebView2 control. Additionally, the pointer-down event needs to be converted into an appropriate `WebViewMouseEventData` event type.
177175

178176
Simple example:
179177

@@ -206,12 +204,30 @@ public class WebViewExample : MonoBehaviour, IPointerDownHandler
206204
}
207205
```
208206

209-
In the above example, pointer-down events are converted into `WebViewMouseEventData` objects and forwarded to the WebView plugin for Unity. It is essentially converted into a mouse-down event. In order to create mouse click events, pointer-up events would need to be handled in a similar fashion.
207+
In the above example, pointer-down events are converted into `WebViewMouseEventData` objects and forwarded to the WebView plugin for Unity. It is essentially converted into a mouse-down event. In order to create mouse click events, pointer-up events would need to be handled in a similar fashion.
210208

211209
In the example above,<!-- todo: present article, or "Get started with WebView2 in HoloLens 2 Unity apps (Preview)"? --> `ConvertToWebViewSpace` is intentionally not implemented.
212210

213211

214212
<!-- ====================================================================== -->
215-
<!-- ## See also -->
216-
<!-- todo: all links in article -->
213+
## See also
214+
<!-- all links in article -->
217215

216+
* [Get started with WebView2 in WinUI 2 (UWP) apps](../get-started/winui2.md)
217+
218+
API Reference:
219+
* [WebView2 API Reference](../webview2-api-reference.md)
220+
* [CoreWebView2.SetVirtualHostNameToFolderMapping Method](/dotnet/api/microsoft.web.webview2.core.corewebview2.setvirtualhostnametofoldermapping)
221+
222+
Hololens docs:
223+
* [Update HoloLens 2](/hololens/hololens-update-hololens)
224+
225+
Mixed Reality docs:
226+
* [Understanding performance for mixed reality](/windows/mixed-reality/develop/advanced-concepts/understanding-performance-for-mixed-reality)
227+
* [Performance recommendations for Unity](/windows/mixed-reality/develop/unity/performance-recommendations-for-unity?tabs=openxr)
228+
* [API Reference for Mixed Reality WebView plugin](/windows/mixed-reality/develop/advanced-concepts/webview2-unity-plugin)
229+
* [Input overview — MRTK2](/windows/mixed-reality/mrtk-unity/mrtk2/features/input/overview)
230+
* [Input — MRTK3](/windows/mixed-reality/mrtk-unity/mrtk3-input/packages/input/overview)
231+
232+
Unity docs:
233+
* [Unity Input System](https://docs.unity3d.com/Packages/com.unity.inputsystem@1.5/manual/index.html)

microsoft-edge/webview2/platforms/win32.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ ms.date: 01/24/2025
1212

1313
The main sample for WebView2 is for Win32.
1414

15-
16-
<!-- ====================================================================== -->
17-
## See also
18-
15+
Articles:
1916
* [Win32 sample app](../samples/webview2apissample.md)
2017
* [Win32 sample app with Visual Composition](../samples/webview2samplewincomp.md)
2118
* [Win32 sample WebView2Browser](../samples/webview2browser.md)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
title: WebView2 in WinForms apps
3+
description: WebView2 in WinForms apps.
4+
author: MSEdgeTeam
5+
ms.author: msedgedevrel
6+
ms.topic: conceptual
7+
ms.service: microsoft-edge
8+
ms.subservice: webview
9+
ms.date: 01/24/2025
10+
---
11+
# WebView2 in WinForms apps
12+
13+
Articles:
14+
* [Win32 sample app](../samples/webview2apissample.md)
15+
* [Win32 sample app with Visual Composition](../samples/webview2samplewincomp.md)
16+
* [Win32 sample WebView2Browser](../samples/webview2browser.md)
17+
* [Get started with WebView2 in Win32 apps](../get-started/win32.md)

microsoft-edge/webview2/platforms/winui2-uwp.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,27 @@ The following classes aren't accessible in WinUI 2:
185185

186186
<!-- ====================================================================== -->
187187
<!-- ## See also -->
188+
<!-- all links in article -->
188189

190+
* [Autofill](../concepts/overview-features-apis.md#autofill) in _Overview of WebView2 APIs_.
191+
* [Printing](../concepts/overview-features-apis.md#printing) in _Overview of WebView2 APIs_.
192+
* [Image capture](../concepts/overview-features-apis.md#image-capture) in _Overview of WebView2 APIs_.
193+
* [Downloads](../concepts/overview-features-apis.md#downloads) in _Overview of WebView2 APIs_.
194+
* [Remote debugging WebView2 WinUI 2 (UWP) apps](../how-to/remote-debugging.md)
195+
196+
API Reference:
197+
* .NET: [WebView2.DefaultBackgroundColor Property](/dotnet/api/microsoft.web.webview2.winforms.webview2.defaultbackgroundcolor)
198+
* Win32: [ICoreWebView2Controller2::_getDefaultBackgroundColor](/microsoft-edge/webview2/reference/win32/icorewebview2controller2#get_defaultbackgroundcolor)
199+
* Win32: [ICoreWebView2Controller2::_putDefaultBackgroundColor](/microsoft-edge/webview2/reference/win32/icorewebview2controller2#put_defaultbackgroundcolor)
200+
201+
Windows docs:
202+
* [SmartScreen](/windows/security/threat-protection/microsoft-defender-smartscreen/microsoft-defender-smartscreen-overview)
203+
* [WebView2.Source property](/windows/winui/api/microsoft.ui.xaml.controls.webview2.source)
204+
* [WebView2.EnsureCoreWebView2Async method](/windows/winui/api/microsoft.ui.xaml.controls.webview2.ensurecorewebview2async)
205+
* [App capability declarations](/windows/uwp/packaging/app-capability-declarations)
206+
207+
MDN:
208+
* [Values](https://developer.mozilla.org/docs/Web/CSS/cursor#values) in _cursor_ CSS property at MDN.
209+
210+
WebView2Feedback repo:
211+
* [CSS - cursor loaded from URL doesn't work](https://github.com/MicrosoftEdge/WebView2Feedback/issues/1925)

0 commit comments

Comments
 (0)