WPF ComboBox update source

孤街浪徒 提交于 2019-12-13 16:13:36

问题


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.

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="??" >

回答1:


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}" >


来源:https://stackoverflow.com/questions/1187294/wpf-combobox-update-source

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!