将鼠标悬停在WPF中的列表框中选择项目 [英] Mouseover to select item in listbox in WPF
本文介绍了将鼠标悬停在WPF中的列表框中选择项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对WPF比较陌生,但是我想知道如何启用列表框以基于鼠标悬停事件而不是单击按钮来选择项目.我希望将鼠标悬停在所选项目上时选择该项目,而无需先按一下.
I am relatively new to WPF, but I would like to know how can I enable a listbox to select an item based on a mouseover event instead of the button click. I would like the item to be selected when the mouse is over the selected item, without having to press click first.
谢谢
推荐答案
您可以在设置IsSelected
属性的IsMouseOver
属性上编写带有触发器的简单ListBoxItem样式:
You may write a simple ListBoxItem Style with a Trigger on the IsMouseOver
property that sets the IsSelected
property:
<ListBox>
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="IsSelected" Value="True"/>
</Trigger>
</Style.Triggers>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
这篇关于将鼠标悬停在WPF中的列表框中选择项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文