【发布时间】:2010-03-20 22:54:18
【问题描述】:
我正在尝试将组合框绑定到对象列表,并且效果很好,除了选定的值之外,我是否缺少某些东西?
<ComboBox ItemsSource="{Binding OrderInfoVm.AllCountries}"
SelectedValuePath="country_code" DisplayMemberPath="country_name"
SelectedValue="{Binding OrderInfoVm.BillingCountry}" />
基本上我想将值绑定到国家代码并将所选值设置为绑定到 OrderInfoVm.BillingCountry(实现 INotifyPropertyChanged)的国家代码
最初当控件加载时选定的值为空,但在单击时会填充 BillingCountry。选定的值似乎没有改变。我该如何补救?
【问题讨论】:
-
`SelectedValue="{Binding OrderInfoVm.BillingCountry.country_code}" 在我在答案中给出的代码中也工作得更好。但是,在这种情况下,文本框不会与组合框同步。使用 SelectedItem!