如何检索单击的链接元素路径(不是链接)。 [英] How to retrieve clicked link element path (Not the link).

查看:70
本文介绍了如何检索单击的链接元素路径(不是链接)。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WPF VB.NET webbrowser控件,显示一个本地HTML文件,其中专辑封面为jpg图像。所有专辑封面都有一个指向包含albumdata的文本文件的链接。单击时,将使用文本文件中的项目填充列表框。



目前我正在使用Webbrowser Navigating事件检索单击的链接为(e.uri) 。但是,我也希望在列表框旁边显示专辑封面。所以我需要检索点击图像的路径。





当前代码:



I have a WPF VB.NET webbrowser control, showing a local HTML file with album covers as jpg images. All album covers have a link to a text file containing the albumdata. When clicked, a listbox is populated with the items in the text file.

Currently I am using the Webbrowser Navigating event to retrieve the clicked link as (e.uri). However, I also want to show the album cover next to the listbox as well. So I need to retrieve the path to the clicked image.


The current code:

Private Sub WhatsNewBrowser_Navigating(sender As Object, e As NavigatingCancelEventArgs) Handles WhatsNewBrowser.Navigating
If e.Uri.ToString.EndsWith(".txt") Then
            e.Cancel = True

            Dim dlg As New WindowWhatsnewAlbumViewer()
            dlg.Owner = Me
            dlg.WindowStartupLocation = Windows.WindowStartupLocation.CenterOwner

            Dim image As New BitmapImage
            image.BeginInit()
            image.UriSource = New Uri("Path to my image goes here")
            image.EndInit()
            dlg.ImgAlbumCover.Source = image

            dlg.ShowDialog()
End If
End sub





如何检索被点击元素的路径?



How do I retrieve the path to the clicked element?

推荐答案

这种方法可能会对您有所帮助: http://stackoverflow.com/questions/9110388/web-br owser-control-how-to-capture-document-events [ ^ ]



看起来,就像WPF WebBrowser控件面临甚至比Windows更糟糕的瑕疵表格版本。链接上的解决方案的概念是使用在应用程序端创建的事件处理程序直接挂钩到DOM。



请注意接受的解决方案下面的注释。它链接在这里: http://www.codegain.com/articles /wpf/ieprogramming/working-with-webbrowser-in-wpf.aspx [ ^ ]。有许多有趣的东西,但你应该看看从Javascript调用C#方法部分。在你的情况下,这可能是一个更好的方法,因为你只使用浏览器控件作为布局引擎。



但你可能会考虑采取另一条路径:你已经有了布局引擎,WPF本身!只需将本地html重新创建为xaml,然后从容器中的代码加载它。而且你拥有所需的一切,甚至更多。
This approach might help you: http://stackoverflow.com/questions/9110388/web-browser-control-how-to-capture-document-events[^]

It looks, like WPF WebBrowser control is facing even vorse flaws than the Windows Forms version. The concept of the solution on the link is to directly hook into the DOM with an event handler created on your app side.

Please note the comment below the accepted solution. It is linking here: http://www.codegain.com/articles/wpf/ieprogramming/working-with-webbrowser-in-wpf.aspx[^]. There are many interesting things, but you should look at Invoke C# method from Javascript section. In your case this could be an even better approach, since you are using the browser control only as a layout engine.

But you might consider taking an other path: you have a layout engine already, WPF itself! Just recreate your local html as xaml, and load it from code in a container. And you have everything you need, even more.


这篇关于如何检索单击的链接元素路径(不是链接)。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆