|
|
|
@ -1074,6 +1074,40 @@ namespace Avalonia.Controls.UnitTests.Primitives |
|
|
|
Assert.Equal(new[] { items[2] }, target.Selection.SelectedItems); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Selection_Is_Not_Cleared_On_Recycling_Containers() |
|
|
|
{ |
|
|
|
using var app = Start(); |
|
|
|
var items = Enumerable.Range(0, 100).Select(x => new ItemViewModel($"Item {x}", false)).ToList(); |
|
|
|
|
|
|
|
// Create a SelectingItemsControl that creates containers that raise IsSelectedChanged,
|
|
|
|
// with a virtualizing stack panel.
|
|
|
|
var target = CreateTarget<TestSelectorWithContainers>( |
|
|
|
itemsSource: items, |
|
|
|
virtualizing: true); |
|
|
|
target.AutoScrollToSelectedItem = false; |
|
|
|
|
|
|
|
var panel = Assert.IsType<VirtualizingStackPanel>(target.ItemsPanelRoot); |
|
|
|
var scroll = panel.FindAncestorOfType<ScrollViewer>()!; |
|
|
|
|
|
|
|
// Select item 1.
|
|
|
|
target.SelectedIndex = 1; |
|
|
|
|
|
|
|
// Scroll item 1 out of view.
|
|
|
|
scroll.Offset = new(0, 1000); |
|
|
|
Layout(target); |
|
|
|
|
|
|
|
Assert.Equal(10, panel.FirstRealizedIndex); |
|
|
|
Assert.Equal(19, panel.LastRealizedIndex); |
|
|
|
|
|
|
|
// The selection should be preserved.
|
|
|
|
Assert.Empty(SelectedContainers(target)); |
|
|
|
Assert.Equal(1, target.SelectedIndex); |
|
|
|
Assert.Same(items[1], target.SelectedItem); |
|
|
|
Assert.Equal(new[] { 1 }, target.Selection.SelectedIndexes); |
|
|
|
Assert.Equal(new[] { items[1] }, target.Selection.SelectedItems); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Selection_State_Change_On_Unrealized_Item_Is_Respected_With_IsSelected_Binding() |
|
|
|
{ |
|
|
|
@ -1248,6 +1282,7 @@ namespace Avalonia.Controls.UnitTests.Primitives |
|
|
|
Setters = |
|
|
|
{ |
|
|
|
new Setter(TestContainer.TemplateProperty, CreateTestContainerTemplate()), |
|
|
|
new Setter(TestContainer.HeightProperty, 100.0), |
|
|
|
}, |
|
|
|
}; |
|
|
|
} |
|
|
|
|