是CefSharp的新手
我创建了一个类库项目并引用了CefSharp库来呈现Web浏览器,但是我面临一些显示Web浏览器的问题.请找到确切的代码
我创建了一个类库项目并引用了CefSharp库来呈现Web浏览器,但是我面临一些显示Web浏览器的问题.请找到确切的代码
WebBrowser_test1:
public partial class ChildWidget : Window { public CefSharp.Wpf.ChromiumWebBrowser webView; public Widget() { InitializeComponent(); CefSharp.CefSettings settings = new CefSharp.CefSettings(); settings.PackLoadingDisabled = true; if (CefSharp.Cef.Initialize(settings)) { webView = new CefSharp.Wpf.ChromiumWebBrowser(); main_grid.Children.Add(webView); webView.Address = "http://www.google.co.uk"; } } }
我在另一个项目中引用这个库(dll)
public MainWindow() { InitializeComponent(); Button newbutton = new Button(); newbutton.Width = 50; main_grid.Children.Add(newbutton); newbutton.Click += ButtonClick; } private void ButtonClick(object sender,RoutedEventArgs e) { try { Webbrowser_test1.ChildWidget childWidget = new Widget(); childWidget.Show(); } catch (Exception) { throw; } }
现在点击按钮,我将打开(WebBrowser_test1)子窗口小部件,我将在其中显示Web浏览器..当窗口打开时,它显示为空白.
如果我遗漏任何东西,请告诉我
@H_404_15@解决方法
创建ChromiumWebBrowser后订阅IsBrowserInitializedChanged.然后,一旦初始化浏览器,您可以调用Load并显示您的控件.
... _browser = new ChromiumWebBrowser(); mainGrid.Children.Add(_browser); _browser.IsBrowserInitializedChanged += OnIsBrowserInitializedChanged; ... void OnIsBrowserInitializedChanged(object sender,DependencyPropertyChangedEventArgs e) { if (_browser.IsBrowserInitialized) { _browser.Load("https://www.google.com/"); } }@H_404_15@ @H_404_15@ 原文链接:https://www.f2er.com/csharp/100546.html