Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF combobox binding from code behind

How can I bind an IList item to a ComboBox through the codebehind.cs file. Please explain with simple steps.

I need the steps for two way binding, not by setting ItemsSource.

I need something like:

myComboBox.SetBinding(ItemsControl.ItemsSourceProperty, 
                      new Binding { Source = myList });

but I need the SelectedItem also.

Thanks

like image 377
joe Avatar asked Dec 30 '22 03:12

joe


1 Answers

Do you mean something like this?

myComboBox.SetBinding(
   ItemsControl.ItemsSourceProperty, 
   new Binding { Source = myList });

myComboBox.SetBinding(
   Selector.SelectedItemProperty,
   new Binding("SelectedItem") { Source = mySelectedItemSource});
like image 69
Samuel Jack Avatar answered Jan 30 '23 18:01

Samuel Jack