簡體   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