瀏覽代碼

Added failing test for #1932.

Steven Kirk 7 年之前
父節點
當前提交
1df826281b
共有 1 個文件被更改,包括 26 次插入0 次删除
  1. 26 0
      tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests.cs

+ 26 - 0
tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests.cs

@@ -707,6 +707,26 @@ namespace Avalonia.Controls.UnitTests.Primitives
             Assert.True(target.SelectedIndex == 1);
         }
 
+        [Fact]
+        public void Binding_With_DelayedBinding_And_Initialization_Where_DataContext_Is_Root_Works()
+        {
+            // Test for #1932.
+            var root = new RootWithItems();
+
+            root.BeginInit();
+            root.DataContext = root;
+
+            var target = new ListBox();
+            target.BeginInit();
+            root.Child = target;
+
+            DelayedBinding.Add(target, ItemsControl.ItemsProperty, new Binding(nameof(RootWithItems.Items)));
+            DelayedBinding.Add(target, ListBox.SelectedItemProperty, new Binding(nameof(RootWithItems.Selected)));
+            target.EndInit();
+            root.EndInit();
+
+            Assert.Equal("b", target.SelectedItem);
+        }
 
         private FuncControlTemplate Template()
         {
@@ -745,5 +765,11 @@ namespace Avalonia.Controls.UnitTests.Primitives
             public IList<Item> Items { get; set; }
             public Item SelectedItem { get; set; }
         }
+
+        private class RootWithItems : TestRoot
+        {
+            public List<string> Items { get; set; } = new List<string>() { "a", "b", "c", "d", "e" };
+            public string Selected { get; set; } = "b";
+        }
     }
 }