Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SelectionModelSelectionChangedEventArgs.SelectedItems indexer. #9699

Merged
merged 2 commits into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Avalonia.Controls/Selection/SelectedItems.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ public T this[int index]
{
return _owner.SelectedItem;
}
else if (Items is object)
else if (Items is not null && Ranges is not null)
{
return Items[index];
return Items[IndexRange.GetAt(Ranges, index)];
}
else
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Specialized;
using System.Linq;
using Avalonia.Collections;
using Avalonia.Controls.Selection;
using Avalonia.Controls.Utils;
Expand Down Expand Up @@ -1144,6 +1145,24 @@ public void Handles_Selection_Made_In_CollectionChanged()
Assert.Equal(new[] { "foo" }, target.SelectedItems);
Assert.Equal(0, target.AnchorIndex);
}

[Fact]
public void SelectedItems_Indexer_Is_Correct()
{
// Issue #7974
var target = CreateTarget();
var raised = 0;

target.SelectionChanged += (s, e) =>
{
Assert.Equal("bar", e.SelectedItems.First());
Assert.Equal("bar", e.SelectedItems[0]);
++raised;
};

target.Select(1);
Assert.Equal(1, raised);
}
}

public class BatchUpdate
Expand Down