diff --git a/tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests.cs b/tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests.cs index 9bafe9baee..007a74224b 100644 --- a/tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests.cs +++ b/tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests.cs @@ -1092,7 +1092,7 @@ namespace Avalonia.Controls.UnitTests.Primitives [Fact] public void Removing_Item_Before_SelectedItem_Should_Update_Container_Selection_When_SelectionModel_Present() { - // Issue #4496. + // Issue #4496 (part 1). var items = new ObservableCollection { "Foo", @@ -1121,6 +1121,34 @@ namespace Avalonia.Controls.UnitTests.Primitives Assert.True(container.IsSelected); } + [Fact] + public void Binding_SelectedIndex_Does_Not_Cause_ArgumentOutOfRange() + { + // Issue #4496 (part 2) + var items = new ObservableCollection(); + + var other = new ListBox + { + Template = Template(), + Items = items, + SelectionMode = SelectionMode.AlwaysSelected, + }; + + var target = new ListBox + { + Template = Template(), + Items = items, + [!ListBox.SelectedIndexProperty] = other[!ListBox.SelectedIndexProperty], + }; + + target.ApplyTemplate(); + target.Presenter.ApplyTemplate(); + other.ApplyTemplate(); + other.Presenter.ApplyTemplate(); + + items.Add("Foo"); + } + [Fact] public void Replacing_Selected_Item_Should_Update_SelectedItem() {