WPF ListBoxItem 双击? [英] WPF ListBoxItem double-click?

查看:31
本文介绍了WPF ListBoxItem 双击?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

WPF 列表框没有 DoubleClick 事件,至少据我所知没有.是否有解决此问题的方法可以让我双击一个项目让事件处理程序对其进行处理?感谢您的帮助.

The WPF ListBox doesn't have a DoubleClick event, at least not as far as I can tell. Is there a workaround for this issue that would let me double-click on an item to have an event handler do something with it? Thanks for your help.

推荐答案

您始终可以覆盖 ListItem 控件模板并处理模板内的双击事件,例如在包含 ListBox 正常内容的不可见边框中.

You could always override the ListItem Control Template and handle the double click event inside the template, for example in an invisible border that contains the normal contents of the ListBox.

本文向您展示如何将 ControlTemplate 与 ListBoxItem 结合使用.除此之外,只需将处理程序添加到控件模板的最外层元素即可.

This article shows you how to use a ControlTemplate with a ListBoxItem. Beyond that, simply add the handler to the outermost element of your control template.

如果您有 Expression Blend,您可以使用它来提取现有的控件模板供您修改,这样您就不必做太多的工作来确保新列表框与旧列表框的行为相同.

If you have Expression Blend, you can use it to extract the existing control template for you to modify so that you do not have to do as much work to ensure that the new list box behaves the same as the old.

这篇关于WPF ListBoxItem 双击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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