我的 UI 上有一个 webBrowser。我问是否有可能它不是直接显示而是通过图像显示,我希望图像仅在收到 LoadCompleted 事件时更新。 怎么办?
最佳答案
我不确定我是否理解你的问题,但如果我理解了,你基本上只想在渲染完成后显示加载的网页。
如果是这样,这段代码应该可以解决问题(我假设您将“LoadCompleted”事件连接到“webBrowser1_LoadCompleted”方法)。此代码使用按钮(“button1”)触发导航,但您可以在任何其他地方使用它。
//here is the code that triggers the navigation: when the button is clicked, I hide the
//webBrowser and then navigate to the page (here I used Google as an example)
private void button1_Click(object sender, RoutedEventArgs e)
{
webBrowser1.Visibility = Visibility.Hidden;
webBrowser1.Navigate(new Uri("http://www.google.it"));
}
private void webBrowser1_LoadCompleted(object sender, NavigationEventArgs e)
{
webBrowser1.Visibility = Visibility.Visible;
}
不过请记住,长时间不向用户显示任何内容(如页面过大)并不总是一个好主意,具体取决于您编写的应用程序的类型。不过,这取决于您。
关于c# - WPF 网页浏览器 : how to display to an image after rendering has finished,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7558529/