2010-02-03 83 views
2

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

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

我需要这样的东西:

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

,但我需要的SelectedItem也。

谢谢

回答

7

你的意思是这样吗?

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

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

上面它的工作原理时,路径=新PATHINFO(“的SelectedItem”) – nag 2012-05-28 11:52:36

+0

@nag,感谢您指出了这一点 - 我已经纠正的代码片段。 – 2012-05-28 13:03:21