I code this code for my ComboBox :
<ComboBox ItemsSource="{Binding Path=AvailableStrings}" SelectedValue="{Binding Path=CurrentStrings}" Name="availableStrings" SelectionChanged="availableStrings_SelectionChanged"/>
And then in the code-behind I have :
private void availableStrings_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
string currentText = availableStrings.SelectedValue as string;
}
I tried to debug and I got the following behaviour in this order :
- 1st,
SelectedValue="{Binding Path=CurrentStrings}"calls theget {...}of my property and JUST after that : availableStrings_SelectionChangedis called andavailableStrings.SelectedValueis null ?!?
My SelectedValue Binding just called the get and get the value oO
It seems like availableStrings_SelectionChanged is called before the value had been assigned the my combobox.. and it sounds like a bug to me no ?
You should use the Set on CurrentStrings to get current values and CurrentStrings should NOT be an array (it should be singular). Bind the SelectedValue TwoWay and don’t use SelectionChanged.