I have an MVVM-bound ComboBox
<ComboBox
ItemsSource="{Binding RootPathItems, Mode=OneTime}"
DisplayMemberPath="DisplayName"
SelectedItem="{Binding SelectedRootPathItem, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
IsSynchronizedWithCurrentItem="True">
</ComboBox>
All items in the ComboBox are memory-unique and created upon starting of the window.
When the user changes the selection in the dropdown the ViewModel property setter is called and the correct object is given to the setter. Then I start some synchronous action based upon the selection and then I want to change the selection to the default selection
private RootPathItem _selectedRootPathItem;
public RootPathItem SelectedRootPathItem
{
get => _selectedRootPathItem;
set
{
if (_selectedRootPathItem != value)
{
_selectedRootPathItem = value;
this.OnPropertyChanged();
SomeAction();
}
}
}
...
//in SomeAction():
this.SelectedRootPathItem = _nothingComboBoxItem;
The .Net internals will call the property getter again and get the _nothingComboBoxItem
but the UI will remain on the previously selected item and not switch to the default.
I also tried to bind SelectedIndex
with the same effect.
My guess is because I’m still in the property setter callstack when I set a new item that this does not work but I don’t actually know what’s going wrong here.