views:

631

answers:

1

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  A: 

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}" >
PaN1C_Showt1Me
I had a different question, but it turned out that you answer helped me anyway, since in my case the blocking was not specifying "UpdateSourceTrigger=PropertyChanged"...
Shimmy