Просмотр исходного кода

Added tests for #1020

Passing. Closes #1020.
Steven Kirk 8 лет назад
Родитель
Сommit
fcee846228

+ 25 - 0
tests/Avalonia.Markup.Xaml.UnitTests/MarkupExtensions/DynamicResourceExtensionTests.cs

@@ -298,6 +298,31 @@ namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions
             Assert.Equal(0xff506070, brush.Color.ToUint32());
         }
 
+
+        [Fact]
+        public void DynamicResource_Can_Be_Assigned_To_ItemTemplate_Property()
+        {
+            var xaml = @"
+<UserControl xmlns='https://github.com/avaloniaui'
+             xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
+    <UserControl.Resources>
+        <DataTemplate x:Key='PurpleData'>
+          <TextBlock Text='{Binding Name}' Background='Purple'/>
+        </DataTemplate>
+    </UserControl.Resources>
+
+    <ListBox Name='listBox' ItemTemplate='{DynamicResource PurpleData}'/>
+</UserControl>";
+
+            var loader = new AvaloniaXamlLoader();
+            var userControl = (UserControl)loader.Load(xaml);
+            var listBox = userControl.FindControl<ListBox>("listBox");
+
+            DelayedBinding.ApplyBindings(listBox);
+
+            Assert.NotNull(listBox.ItemTemplate);
+        }
+
         [Fact]
         public void DynamicResource_Tracks_Added_Resource()
         {

+ 22 - 1
tests/Avalonia.Markup.Xaml.UnitTests/MarkupExtensions/StaticResourceExtensionTests.cs

@@ -37,7 +37,6 @@ namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions
             Assert.Equal(0xff506070, brush.Color.ToUint32());
         }
 
-
         [Fact]
         public void StaticResource_Can_Be_Assigned_To_Attached_Property()
         {
@@ -311,6 +310,28 @@ namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions
             }
         }
 
+        [Fact]
+        public void StaticResource_Can_Be_Assigned_To_ItemTemplate_Property()
+        {
+            var xaml = @"
+<UserControl xmlns='https://github.com/avaloniaui'
+             xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
+    <UserControl.Resources>
+        <DataTemplate x:Key='PurpleData'>
+          <TextBlock Text='{Binding Name}' Background='Purple'/>
+        </DataTemplate>
+    </UserControl.Resources>
+
+    <ListBox Name='listBox' ItemTemplate='{StaticResource PurpleData}'/>
+</UserControl>";
+
+            var loader = new AvaloniaXamlLoader();
+            var userControl = (UserControl)loader.Load(xaml);
+            var listBox = userControl.FindControl<ListBox>("listBox");
+
+            Assert.NotNull(listBox.ItemTemplate);
+        }
+
         [Fact]
         public void Control_Property_Is_Not_Updated_When_Parent_Is_Changed()
         {