简体   繁体   中英

How can I use multiple combo boxes with one datasource in WPF?

When I try to use the same list with multiple combo boxes, the selection is shared with all the combo boxes.

I want the combo box to treat the datasource as their own and selection should not be shared.

<ComboBox ItemsSource="{Binding ActiveLanguages}" DisplayMemberPath="Name" />

ActiveLanguages is a ObservableCollection and is a single instance object for the application.

This Combo Box is on a template, and the selection repeats itself on all the instance of the templates.

IsSynchronizedWithCurrentItem属性设置为false

making a copy can eat a lot of memory depending on the size of the list.

A much better way is to use a BindingSource.

each UI object sets its datasource to a new copy of a BindingSource.

The BindingSources all set their .datasource = the same instance of whatever list you are trying to bind to.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM