4

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

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
joe
  • 41
  • 1
  • 1
  • 3

1 Answers1

10

Do you mean something like this?

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

myComboBox.SetBinding(
   Selector.SelectedItemProperty,
   new Binding("SelectedItem") { Source = mySelectedItemSource});
Samuel Jack
  • 32,712
  • 16
  • 118
  • 155