wpf binding by selected value - swap out bound object without disturbing binding
- by Andy Clarke
Hi,
I've got combo box bound to a custom collection type - its basically an overridden ObservableCollection which I've added a facility to update the underlying collection (via Unity).
I don't want to confuse the issue too much, but thats the background.
My xaml looks like this
<ComboBox ItemsSource="{Binding Manufacturers}" DisplayMemberPath="Name" SelectedValuePath="ID" SelectedValue="{Binding Vehicle.ManufacturerID}" />
And in my overridden collection i was doing this.
index = IndexOf(oldItem);
Insert(index, (T)newItem);
RemoveAt(index + 1);
I had hoped because it was bound by value, that inserting the new object(which had the same id) and then removing the old one would work. But it seems that although its bound by SelectedValue it still knows that its being swapped for a different one. The combo just looses its selection.
Can anyone help please?