Data binding 绑定到Silverlight ComboBox时获取“System.Windows.Controls.TextBlock”的值
我试图在一个非常简单的绑定场景中使用一个带有静态元素列表的Silverlight组合框。问题是所选项目没有返回组合框中文本块的文本,而是返回System.Windows.Controls.TextBlock 我的XAML是:Data binding 绑定到Silverlight ComboBox时获取“System.Windows.Controls.TextBlock”的值,data-binding,silverlight-4.0,Data Binding,Silverlight 4.0,我试图在一个非常简单的绑定场景中使用一个带有静态元素列表的Silverlight组合框。问题是所选项目没有返回组合框中文本块的文本,而是返回System.Windows.Controls.TextBlock 我的XAML是: <ComboBox SelectedValue="{Binding Country, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True}"> <TextBlo
<ComboBox SelectedValue="{Binding Country, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True}">
<TextBlock FontSize="11" Text="Afghanistan" />
<TextBlock FontSize="11" Text="Albania" />
<TextBlock FontSize="11" Text="Algeria" />
</ComboBox>
绑定不会将阿尔巴尼亚作为所选国家/地区,更新组合框选项会将该国家/地区设置为System.Windows.Controls.TextBlock。我尝试过摆弄DisplayMemberPath和SelectedValuePath,但没有找到答案。我怀疑我遗漏了一些非常简单的东西。将组合框项目更改为字符串很有效。我不知道你会如何处理文本块需要格式化的情况
<ComboBox SelectedValue="{Binding Country, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True}">
<System:String>Afghanistan</System:String>
<System:String>Albania</System:String>
<System:String>Algeria</System:String>
</ComboBox>
<ComboBox SelectedValue="{Binding Country, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True}">
<System:String>Afghanistan</System:String>
<System:String>Albania</System:String>
<System:String>Algeria</System:String>
</ComboBox>