C# WindowsFormsHost中带有WebBrowser的WPF应用程序-加载网站时速度非常慢
我有一个WindowsFormsHost,它在WPF应用程序中包含一个WebBrowser控件。我的问题是,如果我第一次尝试加载一个网站,它会非常慢。我还尝试使用WPF WebBrowser,但它也有同样的问题。 在一个只有一个WebBrowser的小示例应用程序中,问题也是一样的&在一个大示例应用程序中,因此我的任何功能都不会影响加载时间。 在我经常使用的谷歌浏览器中,我没有这个问题。Web浏览器的任何属性我都应该考虑设置吗?这与在WPF应用程序中使用WebBrowser有关吗?如有任何建议,我们将不胜感激 谢谢 简单示例应用程序:C# WindowsFormsHost中带有WebBrowser的WPF应用程序-加载网站时速度非常慢,c#,wpf,browser,C#,Wpf,Browser,我有一个WindowsFormsHost,它在WPF应用程序中包含一个WebBrowser控件。我的问题是,如果我第一次尝试加载一个网站,它会非常慢。我还尝试使用WPF WebBrowser,但它也有同样的问题。 在一个只有一个WebBrowser的小示例应用程序中,问题也是一样的&在一个大示例应用程序中,因此我的任何功能都不会影响加载时间。 在我经常使用的谷歌浏览器中,我没有这个问题。Web浏览器的任何属性我都应该考虑设置吗?这与在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>
{
公共部分类主窗口:窗口
{
私有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中),页面并没有加载,运行病毒扫描最终解决了这个问题 如果这没有帮助,请检查ouf CefSharp项目,我会告诉您使用它,因为它更像是“WPF”,它允许您使用WebBrowser做任何事情
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;
}
}