summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue2777.xaml.cs
blob: 590598fe0d5833f639f029cc37ea5b8d762ef80c (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
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
122
123
124
125
126
127
128
129
130
131
132
133
using System;
using System.Collections.Generic;
using Xamarin.Forms;
using System.Collections.ObjectModel;
using System.Linq;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;

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


namespace Xamarin.Forms.Controls.Issues
{
	[Preserve (AllMembers = true)]
	[Issue (IssueTracker.Github, 2777, "When add GroupHeaderTemplate in XAML the group header does not show up")]
	public partial class Issue2777 : TestContentPage
	{
		public Issue2777 ()
		{
			#if APP
			InitializeComponent ();
			var list = SetupList ();
			itemListView.ItemsSource = list;
			#endif
		
		}

		protected override void Init ()
		{
			
		}

		internal void OnItemTapped (object sender, ItemTappedEventArgs ea)
		{
			var listItem = (ListItemValue)ea.Item;
			DisplayAlert (listItem.Name, "You tapped " + listItem.Name, "OK", "Cancel");
		}

		ObservableCollection<ListItemCollection> SetupList ()
		{
			var allListItemGroups = new ObservableCollection<ListItemCollection> ();

			foreach (var item in ListItemCollection.GetSortedData()) {
				// Attempt to find any existing groups where theg group title matches the first char of our ListItem's name.
				var listItemGroup = allListItemGroups.FirstOrDefault (g => g.Title == item.Label);

				// If the list group does not exist, we create it.
				if (listItemGroup == null) {
					listItemGroup = new ListItemCollection (item.Label);
					listItemGroup.Add (item);
					allListItemGroups.Add (listItemGroup);
				} else { // If the group does exist, we simply add the demo to the existing group.
					listItemGroup.Add (item);
				}
			}
			return allListItemGroups;
		}

		// Represents a group of items in our list.
		[Preserve (AllMembers = true)]
		public class ListItemCollection : ObservableCollection<ListItemValue>
		{
			public string Title { get; private set; }

			public string LongTitle { get { return "The letter " + Title; } }

			public ListItemCollection (string title)
			{
				Title = title;
			}

			public static List<ListItemValue> GetSortedData ()
			{
				var items = ListItems;
				items.Sort ();
				return items;
			}

			// Data used to populate our list.
			static readonly List<ListItemValue> ListItems = new List<ListItemValue> () {
				new ListItemValue ("Babbage"),
				new ListItemValue ("Boole"),
				new ListItemValue ("Berners-Lee"),
				new ListItemValue ("Atanasoff"),
				new ListItemValue ("Allen"),
				new ListItemValue ("Cormack"),
				new ListItemValue ("Cray"),
				new ListItemValue ("Dijkstra"),
				new ListItemValue ("Dix"),
				new ListItemValue ("Dewey"),
				new ListItemValue ("Erdős"),
			};
		}

		// Represents one item in our list.
		[Preserve (AllMembers = true)]
		public class ListItemValue : IComparable<ListItemValue>
		{
			public string Name { get; private set; }


			public ListItemValue (string name)
			{
				Name = name;
			}

			int IComparable<ListItemValue>.CompareTo (ListItemValue value)
			{
				return Name.CompareTo (value.Name);
			}

			public string Label {
				get {
					return Name [0].ToString ();
				}
			}
		}
	

		#if UITEST
		[Test]
		public void Issue2777Test ()
		{
			RunningApp.Screenshot ("I am at Issue 2965");
			RunningApp.WaitForElement (q => q.Marked ("The letter A"));
		}
		#endif
	}
}