wpf 多选列表框

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6412156/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 22:54:58  来源:igfitidea点击:

Multiselect ListBox

wpflistboxmulti-select

提问by ni3a

I'm having trouble in multiple items selection in an ListBox.

我在 ListBox 中选择多个项目时遇到问题。

I've tried deriving new control from Selector and writing ListBox helper class which did not work (as expected).

我试过从 Selector 派生新控件并编写 ListBox helper 类,但它不起作用(如预期)。

The issue with Selector class is, it does not expose SelectedItems and it's hell to bind the property and manipulate it with selection changed event.

Selector 类的问题是,它不公开 SelectedItems 并且绑定属性并使用选择更改事件对其进行操作是地狱。

The issue with ListBox Helper class is, I'm getting the required data on multiple selection but it never hits the bound property.

ListBox Helper 类的问题是,我正在获取多项选择所需的数据,但它从未命中绑定属性。

Does anybody know a better way to implement multiselect listbox?

有人知道实现多选列表框的更好方法吗?

Thanks in advance...

提前致谢...

回答by Adrian Faciu

The ListBoxhas multiple selection already implemented. Just change SelectionModeproperty to Multiple or Extened.

列表框具有多重选择已经实施。只需将SelectionMode属性更改为 Multiple 或 Extened。

You can use SelectedItemsproperty to get all the selected items afterwards.

您可以使用SelectedItems属性来获取所有选定的项目。