From 57058f19cda987c1ca199f3957f09bdd12930f00 Mon Sep 17 00:00:00 2001 From: wojciech krysiak Date: Sun, 23 Sep 2018 10:11:49 +0200 Subject: [PATCH] Fix SelectedItemsChanged event arguments in SelectingItemsControl --- .../Primitives/SelectingItemsControl.cs | 4 +-- .../SelectingItemsControlTests_Multiple.cs | 29 +++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) 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 =>