diff --git a/Bonsai.Editor/EditorForm.cs b/Bonsai.Editor/EditorForm.cs index a4607819..af06687d 100644 --- a/Bonsai.Editor/EditorForm.cs +++ b/Bonsai.Editor/EditorForm.cs @@ -2336,7 +2336,7 @@ private async Task OpenDocumentationAsync(string assemblyName, string uid) var editorControl = selectionModel.SelectedView.EditorControl; var url = await documentationProvider.GetDocumentationAsync(assemblyName, uid); if (!ModifierKeys.HasFlag(Keys.Control) && - editorControl.AnnotationPanel.WebViewInitialized) + editorControl.AnnotationPanel.HasWebView) { editorControl.AnnotationPanel.Navigate(url.AbsoluteUri); var nameSeparator = uid.LastIndexOf(ExpressionHelper.MemberSeparator); diff --git a/Bonsai.Editor/GraphView/AnnotationPanel.cs b/Bonsai.Editor/GraphView/AnnotationPanel.cs index 2120efbf..94953255 100644 --- a/Bonsai.Editor/GraphView/AnnotationPanel.cs +++ b/Bonsai.Editor/GraphView/AnnotationPanel.cs @@ -14,6 +14,7 @@ class AnnotationPanel : UserControl readonly RichTextBox textBox; readonly WebView2 webView; bool webViewInitialized; + Action onInitialize; public AnnotationPanel() { @@ -46,7 +47,6 @@ public AnnotationPanel() webView.Margin = new Padding(2); webView.Size = new System.Drawing.Size(296, 70); webView.ZoomFactor = 1D; - webView.EnsureCoreWebView2Async(); webView.CoreWebView2InitializationCompleted += (sender, e) => { webViewInitialized = true; @@ -64,6 +64,9 @@ public AnnotationPanel() { OnTextChanged(EventArgs.Empty); } + + onInitialize?.Invoke(); + onInitialize = null; }; Controls.Add(webView); } @@ -71,14 +74,9 @@ public AnnotationPanel() public ThemeRenderer ThemeRenderer { get; set; } - public WebView2 WebView - { - get { return webView; } - } - - public bool WebViewInitialized + public bool HasWebView { - get { return webViewInitialized; } + get { return webView != null; } } public event LinkClickedEventHandler LinkClicked @@ -104,6 +102,7 @@ public void NavigateToString(string text) var html = MarkdownConvert.ToHtml(Font, text); webView.NavigateToString(html); } + else onInitialize = () => NavigateToString(text); } public void Navigate(string uri) @@ -112,6 +111,7 @@ public void Navigate(string uri) { webView.CoreWebView2.Navigate(uri); } + else onInitialize = () => Navigate(uri); } internal void InitializeTheme() @@ -175,5 +175,11 @@ private void CoreWebView2_WebResourceRequested(object sender, CoreWebView2WebRes } } } + + protected override void OnLoad(EventArgs e) + { + webView.EnsureCoreWebView2Async(); + base.OnLoad(e); + } } }