I have a Custom Control derived from a ComboBox where I use a CompositeCollection to "merge" the original ItemsSource with additional Objects.
The problem is, that
CompositeCollection comp = new CompositeCollection();
SomeLogic();
ItemsSource = comp;
Setting the ItemsSource to the composed Collection is setting SelectedItem to null and invoke the Binding TwoWay Binding to the ViewModel. The SelectedItem bound property in my ViewModel will then be 'null'.
I am currently workarounding this by restoring the SelectedItem after assigning the ItemsSource:
Object priorSelectedItem = SelectedItem;
ItemsSource = comp;
SelectedItem = priorSelectedItem;
However this just fixes the value of SelectedItem in my ViewModel, a nasty sideeffect is that the when the Object changes some logic is run in the Setter. E.G. setting a
_dataHasChanged = true;
Flag.
So if there is any way I can
a) Prevent the SelectedItem to get reset whilst changing the ItemsSource
or
b) Prevent the SelectedItem-Binding to be Invoked whilst changing the ItemsSource
from within the Custom Control (Don't want to take care of 20 ViewModels because there is a flaw in the Control) I would greatly appreciate any input on how to do so :-)