I have a listview control that is bound to an observable collection that I frequently update. When I update the collection, I clear the collection and then add the values. While this is a bit overkill for simple changes, it's very simple and accomplishes the job. In doing so, I lose which item was selected in my listview control and cannot figure out how to maintain the selected state after an update.
I initially thought I could two-way bind the SelectedValue by using the following (WPF):
SelectedValue="{Binding Path=SelectedDevice, Mode=TwoWay}
And then update my collection by:
string PreviouslySelectedDevice = this.SelectedDevice;
aCollection.Clear();
// ... Add Items ...
this.SelectedDevice = PreviouslySelectedDevice;
I was hoping the TwoWay binding would allow me to make changes to backend property which would be automagically reflected in the listView control but this doesn't work. Thanks in advance!