Skip to content

Commit

Permalink
Merge pull request #1913 from WojciechKrysiak/bugfix/CorrectedSelecte…
Browse files Browse the repository at this point in the history
…dItemsControlEvent

Fix SelectedItemsChanged event arguments in SelectingItemsControl
  • Loading branch information
jmacato authored Sep 25, 2018
2 parents 6df48f2 + c3a1f62 commit 71c2019
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Avalonia.Controls/Primitives/SelectingItemsControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<object>());
Assert.Equal(new[] { "bar" }, e.RemovedItems.Cast<object>());
called = true;
};

target.ApplyTemplate();
target.Presenter.ApplyTemplate();
target.SelectedItems[0] = "foo";

Assert.True(called);
}


private FuncControlTemplate Template()
{
return new FuncControlTemplate<SelectingItemsControl>(control =>
Expand Down

0 comments on commit 71c2019

Please sign in to comment.