双击 ListBox 项以打开浏览器 [英] Double Click a ListBox item to open a browser

查看:27
本文介绍了双击 ListBox 项以打开浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 wpf 窗口中有一个 ListBox,它绑定到一个 ObervableCollection.如果有人单击 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?

你的

塞巴斯蒂安

推荐答案

您可以向 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 是代码中的一个方法,它具有 鼠标双击.

ListBoxItem_MouseDoubleClick is a method in your code behind with the correct signature for MouseDoubleClick.

这篇关于双击 ListBox 项以打开浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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