Working with the WebView2 browser control in WinForms
The last control we want to explore in this chapter is WebView2
. This is the same WebView2
that is available natively in WinUI 3. We have already discussed the basics of WebView2
and added it to a WPF project in the previous chapter, so we won't spend time repeating those details. Instead, let's jump straight into how to use it in WinForms:
- Add a new Windows Forms App (.NET Framework) project to the current solution and name it
XamlIslandsSample.WinFormsBrowser
. Be sure to select .NET Framework version 4.6.2 or later when creating the project. - Open NuGet Package Manager, make sure to check the Include prerelease checkbox, and add the newest prelease version of the Microsoft.Web.WebView2 package to the new project.
- Open Form1.cs in the WinForms designer and open the Visual Studio Toolbox window. You will find the WebView2 control under the WebView2Control section of Toolbox: