来自代码隐藏的WPF组合框绑定

来自代码隐藏的WPF组合框绑定,wpf,data-binding,combobox,code-behind,Wpf,Data Binding,Combobox,Code Behind,如何通过codebehind.cs文件将IList项绑定到ComboBox。 请用简单的步骤解释 我需要双向绑定的步骤,而不是通过设置ItemsSource 我需要像这样的东西: myComboBox.SetBinding(ItemsControl.ItemsSourceProperty, new Binding { Source = myList }); 但是我还需要SelectedItem 谢谢你的意思是这样的吗 myComboBox.SetB

如何通过codebehind.cs文件将
IList
项绑定到
ComboBox
。 请用简单的步骤解释

我需要双向绑定的步骤,而不是通过设置
ItemsSource

我需要像这样的东西:

myComboBox.SetBinding(ItemsControl.ItemsSourceProperty, 
                      new Binding { Source = myList });
但是我还需要
SelectedItem


谢谢你的意思是这样的吗

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

myComboBox.SetBinding(
   Selector.SelectedItemProperty,
   new Binding("SelectedItem") { Source = mySelectedItemSource});

@nag,谢谢你指出这一点-我已经更正了代码片段。