From e4e400479cac4aac2e1381fe83ebd3a7b3821eba Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Mon, 17 Aug 2020 16:12:21 +0200 Subject: [PATCH] Added another failing test for #4496. --- .../Primitives/SelectingItemsControlTests.cs | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests.cs b/tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests.cs index 9bafe9baeea..007a74224b3 100644 --- a/tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests.cs +++ b/tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests.cs @@ -1092,7 +1092,7 @@ public void Removing_Item_Before_SelectedItem_Should_Update_SelectedIndex() [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 @@ public void Removing_Item_Before_SelectedItem_Should_Update_Container_Selection_ 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() {