我想在我的 WPF 浏览器中创建一个停止按钮,但找不到要分配给该按钮的事件。我只能找到 Windows 窗体和 Iwebbrowser2 的解决方案,这不是我正在寻找的。
最佳答案
您在哪里查找该事件?您不可能太过努力,因为在最常用的编码资源 MSDN 中很容易可以找到它。这应该始终是您首先看到的地方。来自WebBrowser.Navigating
Event MSDN 上的页面:
Occurs just before navigation to a document.
...
Navigating event handlers are passed an instance of the NavigatingCancelEventArgs class. You can cancel the navigation by setting the Cancel property of the NavigatingCancelEventArgs object to true.
在链接页面中,您会看到它使用类型为 NavigatingCancelEventArgs
的对象,如果您查看 NavigatingCancelEventArgs
Class在 MSDN 上的页面上,您会看到一个名为 Cancel
的属性:
Gets or sets a value indicating whether the event should be canceled. (Inherited from CancelEventArgs.)
然后如果你看到 CancelEventArgs.Cancel
Property页面,您将看到一个具体如何使用它的示例。在你的情况下,你会做这样的事情:
public void NavigatingCancelEventHandler(object sender, NavigatingCancelEventArgs e)
{
e.Cancel = true;
}
以后请实际搜索答案并引用How do I ask a good question? StackOverflow 帮助中心的页面在发布另一个问题之前。
关于c# - 使用 wpf 浏览器取消导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21528849/