来自后面代码的 WPF 组合框绑定 [英] WPF combobox binding from code behind

查看:28
本文介绍了来自后面代码的 WPF 组合框绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How can I bind an IList item to a ComboBox through the codebehind.cs file. Please explain with simple steps.

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

I need the steps for two way binding, not by setting 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});

这篇关于来自后面代码的 WPF 组合框绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆