Browse Source

Merge pull request #2526 from AvaloniaUI/fixes/2522-selecteditem-move

Handling moving selected item in SelectedItemsControl.
pull/2580/head
Jumar Macato 7 years ago
committed by GitHub
parent
commit
6fdec1649c
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      src/Avalonia.Controls/Primitives/SelectingItemsControl.cs
  2. 27
      tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests.cs

1
src/Avalonia.Controls/Primitives/SelectingItemsControl.cs

@ -380,6 +380,7 @@ namespace Avalonia.Controls.Primitives
}
break;
case NotifyCollectionChangedAction.Move:
case NotifyCollectionChangedAction.Reset:
SelectedIndex = IndexOf(Items, SelectedItem);
break;

27
tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests.cs

@ -341,6 +341,33 @@ namespace Avalonia.Controls.UnitTests.Primitives
Assert.Equal(-1, target.SelectedIndex);
}
[Fact]
public void Moving_Selected_Item_Should_Update_Selection()
{
var items = new AvaloniaList<Item>
{
new Item(),
new Item(),
};
var target = new SelectingItemsControl
{
Items = items,
Template = Template(),
};
target.ApplyTemplate();
target.SelectedIndex = 0;
Assert.Equal(items[0], target.SelectedItem);
Assert.Equal(0, target.SelectedIndex);
items.Move(0, 1);
Assert.Equal(items[1], target.SelectedItem);
Assert.Equal(1, target.SelectedIndex);
}
[Fact]
public void Resetting_Items_Collection_Should_Clear_Selection()
{

Loading…
Cancel
Save