【发布时间】:2019-06-15 01:38:42
【问题描述】:
当我在 WPF 中重新创建 webBrowser 控件然后导航到页面时,有时控件创建成功并加载页面,有时控件未完全创建,然后在与 Windows 关联的默认浏览器中加载页面(Firefox on我现在的电脑)。
以下是我删除和重新创建 webBrowser 的方法:
webBrowser.Dispose();
webBrowser = null;
webBrowser = new WebBrowser();
tabItem_webBrowser.Content = webBrowser;
webBrowser.HorizontalAlignment = HorizontalAlignment.Right;
webBrowser.Height = 228;
webBrowser.VerticalAlignment = VerticalAlignment.Top;
webBrowser.Width = 586;
webBrowser.RenderTransformOrigin = new Point(0.5, 0.5);
webBrowser.Margin = new Thickness(0, 41, 10, 0);
webBrowser.Navigated += SuppressScriptErrors;
webBrowser.Visibility = Visibility.Visible;
ScrollViewer.SetHorizontalScrollBarVisibility(webBrowser, ScrollBarVisibility.Visible);
ScrollViewer.SetVerticalScrollBarVisibility(webBrowser, ScrollBarVisibility.Visible);
webBrowser.LoadCompleted += WebBrowser_LoadCompleted;
我尝试查看是否可以检查 webBrowser 是否已使用 webBrowser.IsInitialized 进行了初始化,但出现了同样的问题。
有没有办法确保在执行 webBrowser.navigate(url) 之前完全创建了 webBrowser?
注意:我处理和重新创建它的原因是为了防止内存泄漏。
你能帮我解决这个问题吗?
感谢您的宝贵时间和帮助,非常感谢。
【问题讨论】: