summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue55555.cs
blob: 0aefc55c38388c6260d574b333525d6d5dbee6ac (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
´╗┐using System;
using System.Collections.ObjectModel;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;

#if UITEST
using Xamarin.UITest;
using NUnit.Framework;
#endif

namespace Xamarin.Forms.Controls
{
	[Preserve(AllMembers = true)]
	[Issue(IssueTracker.None, 55555, "Header problem")]
	public class Issue55555 : TestContentPage // or TestMasterDetailPage, etc ...
	{
		protected override void Init()
		{
			var lstView = new ListView(ListViewCachingStrategy.RecycleElement);
			ObservableCollection<GroupedVeggieModel> grouped = CreateData();

			lstView.ItemsSource = grouped;
			lstView.HasUnevenRows = true;
			lstView.IsGroupingEnabled = true;
			lstView.GroupDisplayBinding = new Binding("LongName");
			lstView.GroupShortNameBinding = new Binding("ShortName");

			lstView.ItemTemplate = new DataTemplate(typeof(DemoTextCell));
			lstView.ItemTemplate.SetBinding(DemoTextCell.TextProperty, "Name");

			Content = lstView;
		}

		static ObservableCollection<GroupedVeggieModel> CreateData()
		{
			var grouped = new ObservableCollection<GroupedVeggieModel>();

			var veggieGroup = new GroupedVeggieModel() { LongName = "vegetables", ShortName = "v" };
			veggieGroup.Add(new VeggieModel() { Name = "celery", IsReallyAVeggie = true, Comment = "try ants on a log" });
			veggieGroup.Add(new VeggieModel() { Name = "tomato", IsReallyAVeggie = false, Comment = "pairs well with basil" });
			veggieGroup.Add(new VeggieModel() { Name = "zucchini", IsReallyAVeggie = true, Comment = "zucchini bread > bannana bread" });
			veggieGroup.Add(new VeggieModel() { Name = "peas", IsReallyAVeggie = true, Comment = "like peas in a pod" });

			var fruitGroup = new GroupedVeggieModel() { LongName = "fruit", ShortName = "f" };
			fruitGroup.Add(new VeggieModel() { Name = "banana", IsReallyAVeggie = false, Comment = "available in chip form factor" });
			fruitGroup.Add(new VeggieModel() { Name = "strawberry", IsReallyAVeggie = false, Comment = "spring plant" });
			fruitGroup.Add(new VeggieModel() { Name = "cherry", IsReallyAVeggie = false, Comment = "topper for icecream" });

			grouped.Add(veggieGroup);
			grouped.Add(fruitGroup);

			return grouped;
		}

		[Preserve(AllMembers = true)]
		public class VeggieModel
		{
			public string Name { get; set; }
			public string Comment { get; set; }
			public bool IsReallyAVeggie { get; set; }
			public string Image { get; set; }
		}

		[Preserve(AllMembers = true)]
		public class GroupedVeggieModel : ObservableCollection<VeggieModel>
		{
			public string LongName { get; set; }
			public string ShortName { get; set; }
		}

		[Preserve(AllMembers = true)]
		public class DemoTextCell : TextCell
		{
			public DemoTextCell()
			{
				Height = 150;
			}
		}

#if UITEST
		[Test]
		public void TGroupDisplayBindingPresentRecycleElementTest()
		{
			RunningApp.WaitForElement(q => q.Marked("vegetables"));
		}
#endif
	}
}