KirillOsenkov/PublicBugs

WPF ListBox.SelectedIndex is out-of-sync with View.CurrentPosition

Opened this issue · 0 comments

Have a ListBox where ItemsSource is a CollectionViewSource around some observable collection.

list.IsSynchronizedWithCurrentItem = true;

The view has a filter and LiveShaping:
viewSource.Filter = i => i is RunProfile runProfile && runProfile.IsAvailable;
viewSource.EnableLiveShaping(nameof(RunProfile.IsAvailable));

Adding a new first item to the view updates the SelectedItem on the ListBox but doesn't update the SelectedIndex (which remains 1).

Need this workaround:

        view.CollectionChanged += (s, e) =>
        {
            list.SelectedIndex = view.CurrentPosition;
        };