Browse Source
Merge pull request #9699 from AvaloniaUI/fixes/7974-selectionmodel-eventargs-indexer
Fix SelectionModelSelectionChangedEventArgs.SelectedItems indexer.
pull/9702/head
Max Katz
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
21 additions and
2 deletions
-
src/Avalonia.Controls/Selection/SelectedItems.cs
-
tests/Avalonia.Controls.UnitTests/Selection/SelectionModelTests_Single.cs
|
|
|
@ -35,9 +35,9 @@ namespace Avalonia.Controls.Selection |
|
|
|
{ |
|
|
|
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 |
|
|
|
{ |
|
|
|
|
|
|
|
@ -1,5 +1,6 @@ |
|
|
|
using System; |
|
|
|
using System.Collections.Specialized; |
|
|
|
using System.Linq; |
|
|
|
using Avalonia.Collections; |
|
|
|
using Avalonia.Controls.Selection; |
|
|
|
using Avalonia.Controls.Utils; |
|
|
|
@ -1144,6 +1145,24 @@ namespace Avalonia.Controls.UnitTests.Selection |
|
|
|
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 |
|
|
|
|