WPF组合框绑定从代码后面 [英] WPF combobox binding from code behind
本文介绍了WPF组合框绑定从代码后面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何通过codebehind.cs文件将 IList
项目绑定到 ComboBox
。
请用简单的步骤解释。
我需要双向绑定的步骤,而不是通过设置 ItemsSource
。
我需要类似:
myComboBox.SetBinding ItemsControl.ItemsSourceProperty,
new Binding {Source = myList});
但我还需要 SelectedItem
/ p>
感谢
解决方案
>
myComboBox.SetBinding(
ItemsControl.ItemsSourceProperty,
new Binding {Source = myList});
myComboBox.SetBinding(
Selector.SelectedItemProperty,
new Binding(SelectedItem){Source = mySelectedItemSource});
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});
这篇关于WPF组合框绑定从代码后面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文