简体   繁体   English

WindowsFormsHost中带有WebBrowser的WPF应用-加载网站时非常慢

[英]WPF app with WebBrowser in WindowsFormsHost - very slow at loading website

I have a WindowsFormsHost that contains a WebBrowser control in a WPF app. 我有一个WindowsFormsHost,在WPF应用程序中包含一个WebBrowser控件。 My problem is that if I try to load a website for the first time it is doing it very slow. 我的问题是,如果我第一次尝试加载网站,它的运行速度将非常慢。 I also attempted to use the WPF WebBrowser, but it has the same issue. 我也尝试使用WPF WebBrowser,但它具有相同的问题。 The problem is the same in a small sample app with just one WebBrowser & in a large one, so none of my functionality is affecting the load time. 这个问题在一个只有一个WebBrowser的小型示例应用程序中还是在一个大型示例应用程序中都是相同的,因此我的功能都没有影响加载时间。 In Google Chrome, which I regularly use, I don't have this problem. 在我经常使用的Google Chrome浏览器中,我没有这个问题。 Are any properties of the WebBrowser I should consider setting? 我应该考虑设置WebBrowser的任何属性吗? Is this related to using the WebBrowser in a WPF app? 这与在WPF应用程序中使用WebBrowser有关吗? Any suggestions are appreciated. 任何建议表示赞赏。

Thanks. 谢谢。

Simple sample app : 简单的示例应用程序:

<Window x:Class="WebBrowserIntoWPFConceptTest.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="468" Width="840" xmlns:dxr="http://schemas.devexpress.com/winfx/2008/xaml/ribbon" xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars">
<Grid x:Name="grid">
    <Grid.ColumnDefinitions>
        <ColumnDefinition/>
        <ColumnDefinition/>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="80*"/>
        <RowDefinition Height="20*"/>
    </Grid.RowDefinitions>

    <!--<WebBrowser Grid.Row="0"
                Grid.Column="0"
                Grid.ColumnSpan="2"
                x:Name="wb"/>-->
    <Button Grid.Row="1" 
            Grid.Column="0"
            Width="50" 
            Height="50"
            VerticalAlignment="Bottom"
            Click="Button_Click"/>
    <Button Grid.Row="1"
            Grid.Column="1"
            Width="50" 
            Height="50" Click="Button_Click_1" />
</Grid>

namespace WebBrowserIntoWPFConceptTest

{ public partial class MainWindow : Window { private WindowsFormsHost winFormHost; {公共局部类MainWindow:Window {私人WindowsFormsHost winFormHost; System.Windows.Forms.WebBrowser wf_wb; System.Windows.Forms.WebBrowser wf_wb;

    public MainWindow()
    {
        InitializeComponent();
        wf_wb = new System.Windows.Forms.WebBrowser();
        winFormHost = new WindowsFormsHost();
        winFormHost.Child = wf_wb;
        Grid.SetColumn(winFormHost, 0);
        Grid.SetRow(winFormHost, 0);
        Grid.SetColumnSpan(winFormHost, 2);
        grid.Children.Add(winFormHost);
    }



    private void Button_Click(object sender, RoutedEventArgs e)
    {
        Uri uri = new Uri("http://www.google.com");
        wf_wb.Navigate(uri);
    }

    private void Button_Click_1(object sender, RoutedEventArgs e)
    {
        HtmlDocument htmlDoc = (HtmlDocument)wf_wb.Document;
    }
}

} }

WebBrowser is wrapper of IE. WebBrowser是IE的包装器。 So if you try IE and it is slow, then the WebBrowser is gonna be slow too. 因此,如果您尝试使用IE且速度很慢,则WebBrowser也将变慢。 It could be some kind of virus that's making it slow. 可能是某种病毒使它变慢了。 So scan your computer with virusscanner. 因此,请使用virusscanner扫描计算机。

I have not heard about such problem. 我还没有听说过这样的问题。 However I've had browser problems myself(in IE and mozilla) where page just didn't load and running virus scans fixed it finally. 但是我自己(在IE和Mozilla中)遇到了浏览器问题,其中页面只是没有加载,而运行病毒扫描最终解决了该问题。

If that didn't help, check ouf CefSharp project https://github.com/chillitom/CefSharp I would tell you to use that, because it's more "WPF'"ish. 如果那没有帮助,请检查CefSharp项目https://github.com/chillitom/CefSharp,我会告诉您使用它,因为它更像是“ WPF”。 It allows you to do everything with WebBrowser. 它允许您使用WebBrowser进行所有操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM