确定 WPF WebBrowser 是否正在加载页面
我在窗口中有一个 WPF System.Windows.Controls.WebBrowser 控件。用户可以在 Web 浏览器显示的网页中输入信息并点击提交按钮。页面回发后,它使用脚本对象与我的应用程序进行通信。我需要确保一旦按下提交按钮,表单就不会关闭或以其他方式停止等待网页回发。如果我可以通过“IsLoading”之类的属性检查 WebBrowser 或其文档的状态,并在加载时取消任何操作,那就太好了。我没有看到类似的东西,所以我正在考虑在 Navigating 事件上设置一个标志,并在 Navigated 或 LoadCompleted 事件上取消设置它,但有一种情况是我单击网页上的链接(与 javascript 相关,它不会进入新页面),其中 Navigating 被触发,但 Navigated 和 LoadCompleted 永远不会触发。有没有办法根据需要确定浏览器的状态?
I have a WPF System.Windows.Controls.WebBrowser control in a Window. A user can enter information and hit a submit button into the webpage displayed by the WebBrowser. After the page posts back it uses a scripting object to communicate with my application. I need to make sure that once the submit button has been pressed, the form doesn't close or otherwise stop waiting for the web page to post back. It would be great if I could check the state of the WebBrowser or its document via a property like "IsLoading" and cancel any actions if it is loading. I didn't see anything like that so I was thinking of setting a flag on the Navigating event and unsetting it on the Navigated or LoadCompleted event, but there is a case where I click a link on the web page (tied to javascript, it doesn't go to a new page) where Navigating is fired, but Navigated and LoadCompleted never fire. Is there a way to determine the state of the browser on demand?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据 MSDN 如果导航事件被调用,那么导航事件也将被触发,除非您明确 取消导航。我尝试了下面的代码片段,它似乎工作正常。 (即)每当导航事件在导航事件之后被触发时。
如果这不是您要查找的内容,请提供您遇到问题的网页 URL。
As per MSDN if the Navigating event gets invoked then the Navigated Event will also get fired unless you explicitly Cancel the navigation. I tried the below code-snippet it seems to be working fine. (i.e) whenever the Navigated event is getting fired following Navigating event.
If this is not what you are looking for, then provide the webpage URL in which you are facing the issue.
不,似乎没有办法按需查询 WPF 浏览器的状态。我决定在导航事件处理程序中设置我自己的标志并在导航事件处理程序中取消设置它。它对我来说不能可靠地工作,因为有一个取消导航的脚本(javascript:void(0))。
No, there does not appear to be a way to query the WPF browser's status on demand. I settled on my original idea of setting my own flag in the Navigating event handler and unsetting it in the Navigated event handler. It was not working reliably for me because there was a script that canceled navigation (javascript:void(0)).