blob: bb7ee70b2a18bb5d77200ae6c0aaa03d332a0bb3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
using System;
using NUnit.Framework;
using Xamarin.Forms.Core.UnitTests;
namespace Xamarin.Forms.Xaml.UnitTests
{
[TestFixture]
public class Issue1554
{
[SetUp]
public void Setup()
{
Device.PlatformServices = new MockPlatformServices();
}
[TearDown]
public void TearDown()
{
Device.PlatformServices = null;
}
[Test]
public void CollectionItemsInDataTemplate ()
{
var xaml = @"<?xml version=""1.0"" encoding=""UTF-8""?>
<ListView
xmlns=""http://xamarin.com/schemas/2014/forms""
xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml""
ItemsSource=""{Binding}"">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<StackLayout>
<Label Text=""{Binding}""></Label>
<Label Text=""{Binding}""></Label>
</StackLayout>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>";
var listview = new ListView ();
var items = new [] { "Foo", "Bar", "Baz" };
listview.BindingContext = items;
listview.LoadFromXaml (xaml);
ViewCell cell0 = null;
Assert.DoesNotThrow (() => {
cell0 = (ViewCell)listview.TemplatedItems.GetOrCreateContent (0, items [0]);
});
ViewCell cell1 = null;
Assert.DoesNotThrow (() => {
cell1 = (ViewCell)listview.TemplatedItems.GetOrCreateContent (1, items [1]);
});
Assert.AreNotSame (cell0, cell1);
Assert.AreNotSame (cell0.View, cell1.View);
Assert.AreNotSame (((StackLayout)cell0.View).Children [0], ((StackLayout)cell1.View).Children [0]);
Assert.AreNotSame (((StackLayout)cell0.View).Children [1], ((StackLayout)cell1.View).Children [1]);
}
}
}
|