Reputation: 89
I'm having an issue where my combobox is losing its SelectedIndex value upon closing of the UserControl. The ViewModel still has it, but the view keeps resetting it to -1. I understand there is an issue with the order of binding ItemSource and SelectedIndex, but I'm not binding directly to ItemSource. Basically, I'm trying to figure out the proper syntax for the binding below.
</ComboBox.ItemTemplate>
<ComboBox.ItemsSource>
<CompositeCollection>
<ComboBoxItem IsEnabled="False">Select a database connection...</ComboBoxItem>
<CollectionContainer Collection="{Binding Source={StaticResource ConnectionsBridge}}" />
<ComboBoxItem><New...></ComboBoxItem>
</CompositeCollection>
</ComboBox.ItemsSource>
**<ComboBox.SelectedIndex>
<Binding Path="SelectedConnectionIndex"/>
</ComboBox.SelectedIndex>**
</ComboBox>
Upvotes: 1
Views: 756
Reputation: 12465
Are you binding to an index (int) or an item (object). Your example binds to a property that would indicate an index, not an object.
You should set the Mode property of the SelectedIndex binding
<ComboBox SelectedIndex="{Binding SelectedConnectionIndex, Mode=TwoWay}">
</ComboBox>
Upvotes: 1