每次重新访问应用程序页面时,WebBrowser 控件都必须重新加载内容(Windows Phone 7、Silverlight)
我正在为 Windows Phone 7/Silverlight 编写一个应用程序。当应用程序在包含 WebBrowser 控件的应用程序页面上被逻辑删除并重新激活时(我已将 Uri 保存在应用程序状态)或,同一应用程序页面会导航到通过 NavigationService.GoBack() 或手机后退按钮,似乎只要控件仍然具有 webbrowser.source 值,它就应该渲染得很好,但事实并非如此。除非我使用 Navigate() 方法,否则无论我尝试什么,它都会显示白色/空白屏幕。不幸的是,使用 Navigate() 方法会导致不必要地再次下载 Web 内容。当仅使用 GoBack() 通过 WebBrowser 控件返回应用程序页面时,这尤其令人沮丧,这在我的应用程序中非常常见。
private void OnWebBrowserLoaded(object sender, RoutedEventArgs e)
{
//webBrowser1.Source = CurrentUri; //does not work, results in white/blank browser page
webBrowser1.Navigate(CurrentUri); //works, but page has to reload from web, bad UX
}
关于解决这个问题的方法有什么建议吗?我还尝试将相同的代码放入页面加载处理程序中。它的行为方式同样糟糕。
我还尝试保存 HTML (SaveToString) 并从应用程序状态重新加载它 (NavigateToString),但由于某种原因,网页没有完全呈现,即使 HTML 看起来很好。另外,我想访问 Host 和 Uri 属性。如果我能让 HTML 从 NavigateToString 渲染正常,我可能可以解决这个问题。 谢谢, 杰伊
I'm writing an app for Windows Phone 7/Silverlight. When the app is either tombstoned and reactivated while on the app page containing the WebBrowser control (I've saved the Uri in app state) or that same app page is navigated to by NavigationService.GoBack() or the phone back button, it seems that as long as the control still has the webbrowser.source value, it should then render just fine, but this is not the case. Unless I use the Navigate() method, it shows a white/blank screen, no matter what I try. Unfortunately, using the Navigate() method causes the web content to download again, unnecessarily. It's especially frustrating when only a GoBack() is used to get back to the application page with the WebBrowser control, which is quite frequent in my app.
private void OnWebBrowserLoaded(object sender, RoutedEventArgs e)
{
//webBrowser1.Source = CurrentUri; //does not work, results in white/blank browser page
webBrowser1.Navigate(CurrentUri); //works, but page has to reload from web, bad UX
}
Any suggestions on a way around this problem? I've also tried putting this same code in the page loaded handler. It behaves in the same poor manner.
I've also tried saving off the HTML (SaveToString) and reloading it from app state (NavigateToString), but the web page does not render completely for some reason, even though the HTML appears fine. Also, I'd like to have access to the Host and Uri properties. I could probably work around that, if I could get the HTML to render OK from NavigateToString.
Thanks,
Jay
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该使用 browsertask:
这应该可以解决您的问题。
URL 将是您要访问的页面的 URL。
You should use browsertask:
This should solve your issue.
URL will be the URL of the page you want to visit.