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?
XamComboBoxEditor.SelectedItem works exactly like the native ListBox.SelectedItem. It returns the first object from the controls SelectedItems collection, equivelent to:
xamComboEditor.SelectedItems[0]
the SelectedItems collection gives you all of the currently selected items.
You can set up a twoway binding on the controls SelectedItem property.
Devin
Thank you. But there is no SelectedItems avaliable in Intellicense in xaml for XamComboBoxEditor.
Is SelectedItems a dependency property and available for binding?
For example, entity is Department(deptid, deptName,,,)., SelectedDepartment is property in ViewModel. xaml like:
SelectedItem="{Binding SelectedDepartment, Mode=TwoWay}" DisplayMemberPath="DeptName"Then from the binding, I want to get the selected ID result, like (1,2,....)SelectedDepartment is bound to SelectedItem, not SelectedItems.With this kind of binding, how can I get SelectedItems in ViewModel?
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.