I am trying to add a WebView to a WinForm in order to use a modern browser in an application.
Starting with a blank WinForm, I added code to create the WebView and add it to the form's controls.
using System;
using System.ComponentModel;
using System.Windows.Forms;
namespace TestWebView
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
var wvc = new Microsoft.Toolkit.Win32.UI.Controls.WinForms.WebView();
((ISupportInitialize)wvc).BeginInit();
wvc.Dock = DockStyle.Fill;
Controls.Add(wvc);
((ISupportInitialize)wvc).EndInit();
// You can also use the Source property
wvc.Navigate(new Uri("https://www.microsoft.com"));
}
}
}
This compiles and runs, but the EndInit() call does not finish. No exceptions are thrown. The call enters but does not leave.
The project is set for .NET Framework 4.7.1. I used the NuGet Manager to add Microsoft.Toolkit.WIn32.UI.Controls v4.0.2 to the project. I am following the instructions on https://blogs.windows.com/msedgedev/2018/05/09/modern-webview-winforms-wpf-apps/
Why is this not working?
I am running Visual Studio as Administrator.
If I run VS normally, the WebView works.
So, now I have a different problem: How do I run a WebView as Administrator?
Thank you to Steve and Jimi for the helpful comments.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With