-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Issue7393.cs
121 lines (91 loc) · 2.52 KB
/
Issue7393.cs
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
using System;
using System.Collections.Generic;
using System.Text;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
using System.Collections.ObjectModel;
using System.Threading.Tasks;
#if UITEST
using Xamarin.Forms.Core.UITests;
using Xamarin.UITest;
using NUnit.Framework;
#endif
namespace Xamarin.Forms.Controls.Issues
{
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 7393, "[Bug] CollectionView problems and crashes with IsGrouped=\"true\"",
PlatformAffected.iOS)]
public class Issue7393 : TestContentPage
{
ObservableCollection<_7393Group> _source;
Label _result;
const string Success = "Success";
protected override void Init()
{
var cv = new CollectionView();
_source = new ObservableCollection<_7393Group>();
cv.GroupHeaderTemplate = new DataTemplate(() => {
var label = new Label();
label.SetBinding(Label.TextProperty, new Binding("Header"));
return label;
});
cv.GroupFooterTemplate = new DataTemplate(() => {
var label = new Label();
label.SetBinding(Label.TextProperty, new Binding("Footer"));
return label;
});
cv.ItemTemplate = new DataTemplate(() => {
var label = new Label();
label.SetBinding(Label.TextProperty, new Binding("Name"));
return label;
});
cv.ItemsSource = _source;
cv.IsGrouped = true;
_result = new Label { Text = "Waiting..." };
var layout = new StackLayout();
layout.Children.Add(_result);
layout.Children.Add(cv);
Content = layout;
Appearing += Issue7393Appearing;
}
async void Issue7393Appearing(object sender, EventArgs e)
{
await AddItems();
_result.Text = Success;
}
async Task AddItems()
{
var groupIndex = _source.Count + 1;
if (groupIndex > 2)
{
return;
}
await Task.Delay(1000);
var group = new _7393Group { Header = $"{groupIndex} Header (added)", Footer = $"{groupIndex} Footer (added)" };
for (int itemIndex = 0; itemIndex < 3; itemIndex++)
{
var item = new _7393Item { Name = $"{groupIndex}.{itemIndex} Item (added)" };
group.Add(item);
}
_source.Add(group);
await AddItems();
}
class _7393Item
{
public string Name { get; set; }
}
class _7393Group : ObservableCollection<_7393Item>
{
public string Header { get; set; }
public string Footer { get; set; }
}
#if UITEST
[Category(UITestCategories.CollectionView)]
[Test]
public void AddingItemsToGroupedCollectionViewShouldNotCrash()
{
RunningApp.WaitForElement(Success, timeout: TimeSpan.FromSeconds(30));
}
#endif
}
}