所以我有一个打开一个新窗口的WPF应用程序。 然后在该新窗口中,它创建一个webBrowser对象:
WebBrowser browser = new WebBrowser(); browser.Source = new System.Uri(chatUrl); browser.Navigating += new NavigatingCancelEventHandler(browser_Navigating); this.browserControl.Child = browser;如您所见,我为NavigatingCancelEventHandler创建了一个钩子。 基于我所看到的,这个处理程序应该拦截在webbrowser中点击的链接。
private void browser_Navigating(object sender, NavigatingCancelEventArgs e) { e.Cancel = true; System.Diagnostics.Process.Start(e.Uri.ToString()); }所以我进行导航,取消它并使用Process.Start函数在我的默认浏览器中打开它。 问题是,它没有这样做。 它仍然在IE9中打开。 我在StackOverflow上看过其他线程,他们都说要做我正在做的事情。 但我正在做的事情不起作用。 请帮忙。
So I have a WPF application that opens up a new window. Then on that new window, it creates a webBrowser object:
WebBrowser browser = new WebBrowser(); browser.Source = new System.Uri(chatUrl); browser.Navigating += new NavigatingCancelEventHandler(browser_Navigating); this.browserControl.Child = browser;As you can see, I have created a hook for NavigatingCancelEventHandler. Based on what I've seen, this handler is supposed to intercept links clicked within the webbrowser.
private void browser_Navigating(object sender, NavigatingCancelEventArgs e) { e.Cancel = true; System.Diagnostics.Process.Start(e.Uri.ToString()); }So I take the navigation, cancel it and use the Process.Start function to open it in my default browser. The problem is, it doesn't do this. It still opens up in IE9. I've seen other threads here on StackOverflow, and they all say to do what I'm doing. But what I'm doing doesn't work. Please help.
最满意答案
您正在为事件处理程序使用不正确的委托类型,您正在指定NavigatingCancelEventArgs但它应该是WebBrowserNavigatingEventHandler。
找到正确方法的最简单方法就是输入
browser.Navigating +=然后按TAB两次,它将为您生成正确的处理程序。
编辑:嗯,我正在看SWF版本,但我会在WPF的任何一种情况下尝试上述内容。
You're using the incorrect delegate type for your event handler, you're specifying a NavigatingCancelEventArgs but it should be a WebBrowserNavigatingEventHandler.
Easiest way to get the right one is to just type
browser.Navigating +=And press TAB twice, it'll generate the correct handler for you.
Edit: Hmm, I'm looking at the S.W.F version, but i'd try the above in either case for WPF.
更多推荐
发布评论