双击某个列表框项打开一个浏览器 [英] Double Click a ListBox item to open a browser
问题描述
我有绑定到 ObervableCollection
A 的ListBox
在我的WPF窗口。我想打开浏览器,如果有人点击了的ListBox
(就像一个链接)的元素。谁能告诉我如何做到这一点?我发现了一些与listboxviews,它只能以这种方式工作或者是有办法通过只使用的ListBox
?
I have a ListBox
in my wpf window that binds to an ObervableCollection
. I want to open the browser if someone clicks on an element of the ListBox
(just like a link). Can someone tell me how to do this? I found something with listboxviews, does it only work this way or is there a way by just using the ListBox
?
此致
塞巴斯蒂安
推荐答案
您可以添加一个风格<一个href=\"http://msdn.microsoft.com/en-us/library/system.windows.controls.itemscontrol.itemcontainerstyle.aspx\">ListBox.ItemContainerStyle,并添加 EventSetter 有:
You can add a style to ListBox.ItemContainerStyle, and add an EventSetter there:
<ListBox>
....
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}" BasedOn="{StaticResource {x:Type ListBoxItem}}">
<EventSetter Event="MouseDoubleClick" Handler="ListBoxItem_MouseDoubleClick"/>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
ListBoxItem_MouseDoubleClick是在你的code与<一个正确的签名后面的方法href=\"http://msdn.microsoft.com/en-us/library/system.windows.controls.control.mousedoubleclick.aspx\">MouseDoubleClick.
这篇关于双击某个列表框项打开一个浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!