public WebView2Handler() { WebView2Loader.EnsureWebView2Runtime(); Control = new WebView2Control(); Control.CoreWebView2Ready += Control_CoreWebView2Ready; InitializeAsync(); }
public WebView2Handler() { WebView2Loader.EnsureWebView2Runtime(); Control = new WebView2Control(); Control.CoreWebView2InitializationCompleted += Control_CoreWebView2Ready; #if WPF _host = new WebView2Host(); _host.Child = Control; _host.Handler = this; #endif }
private WebView.IHandler Create_WebView2() { try { return(WebView2Loader.Create()); } catch { Debug.WriteLine("Warning: Could not create WebView2 handler. Add Microsoft.Web.WebView2 nuget package to your project to take advantage of the latest web control."); // switch to SWF version for subsequent controls UseSwfWebView(); return(new WebViewHandler()); } }
private async void timer_Elapsed(object sender, EventArgs e) { if (WebView2Loader.Detect()) { timer?.Stop(); // wait for things to percolate await Task.Delay(2000); // ensure we didn't get closed already.. if (timer != null) { Close(); } } }
private WebView.IHandler Create_WebView2() { #if NET45 Debug.WriteLine("Warning: .NET 4.5 target cannot use WebView2. Target at least .NET 4.6.2, .NET Core, or .NET 5 instead and install the Microsoft.Web.WebView2 nuget package. Falling back to the Windows Forms WebView."); UseSwfWebView(); return(new WebViewHandler()); #else try { return(WebView2Loader.Create()); } catch { Debug.WriteLine("Warning: Could not create WebView2 handler. Add Microsoft.Web.WebView2 nuget package to your project to take advantage of the latest web control."); // switch to SWF version for subsequent controls UseSwfWebView(); return(new WebViewHandler()); } #endif }
protected override void CreateHandle() { base.CreateHandle(); if (!DesignMode) { if (_webViewEnvironment == null) { BeforeEnvironmentCreatedEventArgs eventArgs = new BeforeEnvironmentCreatedEventArgs(); OnBeforeEnvironmentCreated(eventArgs); string browserExecutableFolder = eventArgs.BrowserExecutableFolder ?? string.Empty; string userDataFolder = eventArgs.UserDataFolder ?? string.Empty; string browserArguments = eventArgs.BrowserArguments ?? string.Empty; //WebView2Loader.CreateEnvironmentWithDetails(string.Empty, string.Empty, string.Empty, OnWebView2EnvironmentCreated); WebView2Loader.CreateEnvironmentWithDetails(browserExecutableFolder, userDataFolder, browserArguments, OnWebView2EnvironmentCreated); } else { _webViewEnvironment.CreateWebView(Handle, OnWebViewCreated); } } }
private void OnInstall(object sender, EventArgs e) { WebView2Loader.InstallWebView2WithUI(this); Close(); }
public ManualInstallDialog() { WebView2Loader.CenterDialog(this); string Loc(string str) => Application.Instance.Localize(typeof(WebView2Loader), str); Title = Loc("Install WebView2 Runtime"); MinimumSize = new Size(300, 200); // controls var installButton = new Button { Text = Loc("Download && Install Now") }; installButton.Click += OnInstall; var downloadButton = new LinkButton { Text = Loc("Open the WebView2 download page to install manually") }; downloadButton.Click += OnDownload; var cancelButton = new Button { Text = Loc("Fallback to IE") }; cancelButton.Click += OnCancel; var description = new Label { TextAlignment = TextAlignment.Center, Text = Loc("This application requires the Microsoft Edge WebView2 Runtime.\nPlease install it to continue.") }; // layout var layout = new DynamicLayout { Padding = 10, DefaultSpacing = new Size(5, 5) }; layout.AddSpace(); layout.Add(description); layout.AddSpace(); layout.AddSeparateRow(null, downloadButton); Content = layout; DefaultButton = installButton; PositiveButtons.Add(installButton); NegativeButtons.Add(cancelButton); Shown += (sender, e) => installButton.Focus(); timer = new UITimer { Interval = 1.0 }; timer.Elapsed += timer_Elapsed; timer.Start(); }
public WebView2Handler() { WebView2Loader.EnsureWebView2Runtime(); Control = new WebView2Control(); Control.CoreWebView2InitializationCompleted += Control_CoreWebView2Ready; }