SL ComboBox SelectedItem is bound to a single object.
What's the SelectedItem for xamComBoEditor if mutiple-selection allowed?
how to set up binding for SelectedItem and how to get the selected items in code from xamComBoEditor if AllowMultipleSelection is set as true?
Hi I have done this long time ago. Here is my solution for multiple selection binding with that behavior in place:
<ig:XamComboEditor x:Name="EAComboBox" AllowMultipleSelection="True" CheckBoxVisibility="Visible" ItemsSource="{Binding MyListenItems, Mode=TwoWay}" DisplayMemberPath="ItemName" SelectedItem="{Binding SelectedItem, Mode=TwoWay}" IsEditable="False" Loaded="EAComboBox_Loaded"> <i:Interaction.Behaviors> <Common:XamComboEditorSelectedItemsBehavior x:Name="cbbehavior" SelectedItems="{Binding SelectedItems, Mode=TwoWay}" /> </i:Interaction.Behaviors></ig:XamComboEditor> private void EAComboBox_Loaded(object sender, RoutedEventArgs e) { XamComboEditorSelectedItemsBehavior be = this.FindName("cbbehavior") as XamComboEditorSelectedItemsBehavior; MyVM vm = this.DataContext as MyVM; var temp = new ObservableCollection<MyItem>(); Transfer(vm.SelectedItems, temp); vm.SelectedItems.Clear(); Transfer(temp, vm.SelectedItems); vm.Reset(); } private void Transfer(IList source, IList target) { if (source == null || target == null) return; target.Clear(); foreach (var o in source) { target.Add(o); } }
Good luck!
Hi,
Any updates on this? Could you please take this on priority?
Thanks,
Komal
Hi Devin,
I tried this behavior but it doesn't work in two-way mode. If I add items to the bound selected items collection from my view model, it does not get reflected in the XamComboEditor.
Could you please help.
Thanks,Komal
As try to figure out why it is not working for initial data loading, I found that following event never happened in demo code for behaviour:
void ContextSelectedItems_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { UnsubscribeFromEvents(); Transfer(SelectedItems as IList, Combobox.SelectedItems); SubscribeToEvents(); }
Hi, I have tried your solution. It is fine for almost everything except one problem:
If I have Data and SelectedData stored in DB, when I load data from DB by VM, initially I can't put more than one item selected in the combo dropdown even data in SelectedData is okay.