wpf binding by selected value - swap out bound object without disturbing binding

Posted by Andy Clarke on Stack Overflow See other posts from Stack Overflow or by Andy Clarke
Published on 2010-04-27T15:00:43Z Indexed on 2010/04/27 15:03 UTC
Read the original article Hit count: 625

Filed under:
|
|
|

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?

© Stack Overflow or respective owner

Related posts about wpf

Related posts about binding