diff --git a/src/Eto.Wpf/Forms/Controls/WebView2Handler.cs b/src/Eto.Wpf/Forms/Controls/WebView2Handler.cs index 8e77ccbf65..41ba6deb82 100755 --- a/src/Eto.Wpf/Forms/Controls/WebView2Handler.cs +++ b/src/Eto.Wpf/Forms/Controls/WebView2Handler.cs @@ -17,6 +17,7 @@ using System.IO; using System.Runtime.Serialization; + #if WINFORMS using WebView2Control = Microsoft.Web.WebView2.WinForms.WebView2; using BaseHandler = Eto.WinForms.Forms.WindowsControl; @@ -385,10 +386,7 @@ public WebView2InitializationException(string message, Exception inner) : base(m public class WebView2Handler : BaseHandler, WebView.IHandler { bool webView2Ready; - protected bool WebView2Ready - { - get { return webView2Ready; } - } + protected bool WebView2Ready => webView2Ready; List delayedActions; @@ -397,20 +395,26 @@ public WebView2Handler() WebView2Loader.EnsureWebView2Runtime(); Control = new WebView2Control(); Control.CoreWebView2InitializationCompleted += Control_CoreWebView2Ready; - InitializeAsync(); } public static CoreWebView2Environment CoreWebView2Environment; - async void InitializeAsync() + /// + /// Override to use your own WebView2 initialization, if necessary + /// + /// Task + protected async virtual Task OnInitializeWebView2Async() { await Control.EnsureCoreWebView2Async(CoreWebView2Environment); } + async void InitializeAsync() => await OnInitializeWebView2Async(); + protected override void Initialize() { base.Initialize(); Size = new Size(100, 100); + InitializeAsync(); } void Control_CoreWebView2Ready(object sender, CoreWebView2InitializationCompletedEventArgs e) @@ -454,6 +458,13 @@ private void CoreWebView2_DocumentTitleChanged(object sender, object e) protected void RunWhenReady(Action action) { + if (webView2Ready) + { + // already ready, run now! + action(); + return; + } + if (delayedActions == null) { delayedActions = new List();