diff --git a/src/Avalonia.Controls/Primitives/SelectingItemsControl.cs b/src/Avalonia.Controls/Primitives/SelectingItemsControl.cs index bb39b005cc7..d7db04f369e 100644 --- a/src/Avalonia.Controls/Primitives/SelectingItemsControl.cs +++ b/src/Avalonia.Controls/Primitives/SelectingItemsControl.cs @@ -871,8 +871,8 @@ private void SelectedItemsCollectionChanged(object sender, NotifyCollectionChang RaisePropertyChanged(SelectedItemProperty, oldItem, item, BindingPriority.LocalValue); } - added = e.OldItems; - removed = e.NewItems; + added = e.NewItems; + removed = e.OldItems; break; } diff --git a/tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests_Multiple.cs b/tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests_Multiple.cs index 3c6b278e07c..9ef7d567c8c 100644 --- a/tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests_Multiple.cs +++ b/tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests_Multiple.cs @@ -541,6 +541,35 @@ public void Assigning_SelectedItems_Should_Raise_SelectionChanged() Assert.True(called); } + [Fact] + public void Replacing_SelectedItems_Should_Raise_SelectionChanged_With_CorrectItems() + { + var items = new[] { "foo", "bar", "baz" }; + + var target = new TestSelector + { + Items = items, + Template = Template(), + SelectedItem = "bar", + }; + + var called = false; + + target.SelectionChanged += (s, e) => + { + Assert.Equal(new[] { "foo",}, e.AddedItems.Cast()); + Assert.Equal(new[] { "bar" }, e.RemovedItems.Cast()); + called = true; + }; + + target.ApplyTemplate(); + target.Presenter.ApplyTemplate(); + target.SelectedItems[0] = "foo"; + + Assert.True(called); + } + + private FuncControlTemplate Template() { return new FuncControlTemplate(control =>