开发者

WPF combobox binding from code behind

开发者 https://www.devze.com 2022-12-19 15:01 出处:网络
How can I bind an IList item to a ComboBox through the codebehind.cs file. Please explain with simple steps.

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


Do you mean something like this?

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

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

精彩评论

暂无评论...
验证码 换一张
取 消