将WPF ListBox SelectedItem绑定到列表

时间:2021-05-20 16:05:08

I have a listbox that has its SelectionMode property set to Multiple.

我有一个列表框,其SelectionMode属性设置为多个。

Is it possible to bind the SelectedItem property to a List? and not to a single item?

是否可以将SelectedItem属性绑定到List?而不是一个项目?

Thanks

2 个解决方案

#1


5  

I've been using Samuel's solution for this and it works very well.

我一直在使用Samuel的解决方案而且效果很好。

http://blog.functionalfun.net/2009/02/how-to-databind-to-selecteditems.html

#2


1  

You can use ListBox.SelectedItems property for this.

您可以使用ListBox.SelectedItems属性。

    <ListBox x:Name="listBox" SelectionMode="Multiple" ItemsSource="{Binding YourCollection}" />
    <ListBox ItemsSource="{Binding SelectedItems , ElementName=listBox}"/>

#1


5  

I've been using Samuel's solution for this and it works very well.

我一直在使用Samuel的解决方案而且效果很好。

http://blog.functionalfun.net/2009/02/how-to-databind-to-selecteditems.html

#2


1  

You can use ListBox.SelectedItems property for this.

您可以使用ListBox.SelectedItems属性。

    <ListBox x:Name="listBox" SelectionMode="Multiple" ItemsSource="{Binding YourCollection}" />
    <ListBox ItemsSource="{Binding SelectedItems , ElementName=listBox}"/>