不允许取消选择/取消选择列表框 [英] Do not allow unselect/deselect in ListBox
本文介绍了不允许取消选择/取消选择列表框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有一种方法来配置WPF 列表框
,使得它不可能取消选择/取消选择一个项目?所以总有一个项目选择?
Is there a way to configure the WPF ListBox
such that it's not possible to deselect/unselect an item? So there is always an item selected?
我的列表框
绑定到的ObservableCollection< MyClass的>
推荐答案
您可以处理的SelectionChanged
事件,并选择是否的SelectedItem
的计算结果为空
。要重新选择已为未选中,你可以跟踪最后选择的项目在私人领域的项目,应该始终在的SelectionChanged
事件进行更新。
You can handle the SelectionChanged
event and set a selection if the SelectedItem
evaluates to null
. To reselect an item that has been unselected you can keep track of the last selected item in a private field, which should always be updated in the SelectionChanged
event.
这篇关于不允许取消选择/取消选择列表框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文