繁体   English   中英

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

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

我有一个WindowsFormsHost,在WPF应用程序中包含一个WebBrowser控件。 我的问题是,如果我第一次尝试加载网站,它的运行速度将非常慢。 我也尝试使用WPF WebBrowser,但它具有相同的问题。 这个问题在一个只有一个WebBrowser的小型示例应用程序中还是在一个大型示例应用程序中都是相同的,因此我的功能都没有影响加载时间。 在我经常使用的Google Chrome浏览器中,我没有这个问题。 我应该考虑设置WebBrowser的任何属性吗? 这与在WPF应用程序中使用WebBrowser有关吗? 任何建议表示赞赏。

谢谢。

简单的示例应用程序:

<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

{公共局部类MainWindow:Window {私人WindowsFormsHost winFormHost; 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是IE的包装器。 因此,如果您尝试使用IE且速度很慢,则WebBrowser也将变慢。 可能是某种病毒使它变慢了。 因此,请使用virusscanner扫描计算机。

我还没有听说过这样的问题。 但是我自己(在IE和Mozilla中)遇到了浏览器问题,其中页面只是没有加载,而运行病毒扫描最终解决了该问题。

如果那没有帮助,请检查CefSharp项目https://github.com/chillitom/CefSharp,我会告诉您使用它,因为它更像是“ WPF”。 它允许您使用WebBrowser进行所有操作。

暂无
暂无

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

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