WPF ComboBox更新源 [英] WPF ComboBox update source

查看:325
本文介绍了WPF ComboBox更新源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 ComboBox ,其中包含国家/地区代码和电话号码(+43 ..,..)
ItemsSource 属性(代码是其中之一)
ComboBox所在的 DataContext 是一个具有PhoneNumber属性的对象。

I have a ComboBox with country codes and phone numbers (+43.., ..) The ItemsSource is a list of Country objects with many properties (Code is one of them.) The DataContext in which the ComboBox is located is an object with the PhoneNumber property.

当用户在列表中选择一个国家时,我想用Country对象的'+43'值更新源PhoneNumber属性(它是一个字符串)。
出现列表,但源不会更新。怎么做?
当我用这个TextBox替换它,一切工作正常:

When user selects a country in the list, I want to update the source PhoneNumber Property(which is a string) with the '+43' value from the Country object. The list appears, but the source is never updated. How to do that? When I replace it with this TextBox, everything works fine:

<TextBox Text="{Binding Path=CountryCode, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" />

<ComboBox ItemsSource="{x:Static Member=data:Country.AllCountries}" SelectedValuePath="Country.Value.Code" SelectedValue="??" >


推荐答案

OK我自己找到了解决方案:

OK I found the solution by myself:

<ComboBox ItemsSource="{x:Static Member=data:Country.AllCountries}" SelectedValuePath="PhonePrefix" SelectedValue="{Binding Path=CountryCode, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" >

这篇关于WPF ComboBox更新源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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