summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla26868.cs
blob: 000b30abd6e4ef54caa29f2d97ffbf3ff76c0318 (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
using System.Collections.Generic;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;

namespace Xamarin.Forms.Controls
{
	[Preserve (AllMembers = true)]
	[Issue (IssueTracker.Bugzilla, 26868, "GroupHeaders do not extend on Windows Phone")]
	public class Bugzilla26868 : TestContentPage
	{
		protected override void Init ()
		{
			List<GroupedData> groups = new List<GroupedData> ();

			var group1 = new GroupedData { GroupName = "Group #1" };
			group1.Add (new GroupItem { DisplayText = "Text for ListView item 1.1" });
			group1.Add (new GroupItem { DisplayText = "Text for ListView item 1.2" });
			groups.Add (group1);

			var group2 = new GroupedData { GroupName = "Group #2" };
			group2.Add (new GroupItem { DisplayText = "Text for ListVIew item 2.1" });
			group2.Add (new GroupItem { DisplayText = "Text for ListView item 2.2" });
			groups.Add (group2);

			var itemTemplate = new DataTemplate(typeof(GroupItemTemplate));
			itemTemplate.CreateContent();

			var groupHeaderTemplate = new DataTemplate(typeof(GroupHeaderTemplate));
			groupHeaderTemplate.CreateContent();

			var listView = new ListView {
				IsGroupingEnabled = true,
				GroupDisplayBinding = new Binding ("GroupName"),
				GroupShortNameBinding = new Binding ("GroupName"),
				HasUnevenRows = Device.OnPlatform (Android: true, WinPhone: false, iOS: false),

				ItemTemplate = itemTemplate,
				GroupHeaderTemplate = groupHeaderTemplate,

				ItemsSource = groups
			};

			Content = new StackLayout {
				VerticalOptions = LayoutOptions.Center,
				Children = {
					new Label {
						Text = "The group headers below should extend to the width of the screen. If they aren't the width of the screen, this test has failed."
					},
					new ContentView {
						Content = listView,
						HorizontalOptions = LayoutOptions.FillAndExpand,
						Padding = 0
					}
				}
			};
		}

		[Preserve (AllMembers = true)]
		public class GroupItem
		{
			public string DisplayText { get; set; }
		}

		[Preserve (AllMembers = true)]
		public class GroupedData : List<GroupItem>
		{
			public string GroupName { get; set; }
		}

		[Preserve (AllMembers=true)]
		public class GroupItemTemplate : ViewCell
		{
			public GroupItemTemplate()
			{
				var title = new Label() { FontSize = 14 };
				title.SetBinding(Label.TextProperty, new Binding("DisplayText", BindingMode.OneWay));

				View = new StackLayout
				{
					Orientation = StackOrientation.Horizontal,
					Padding = new Thickness(8),
					Children = { title } 
				};
			}
		}

		[Preserve(AllMembers = true)]
		public class GroupHeaderTemplate : ViewCell
		{
			public GroupHeaderTemplate()
			{
				var title = new Label { TextColor = Color.White, FontSize = 16 };
				title.SetBinding(Label.TextProperty, new Binding("GroupName", BindingMode.OneWay));

				View = new StackLayout
				{
					Padding = new Thickness(8, 0),
					VerticalOptions = LayoutOptions.StartAndExpand,
					BackgroundColor = Color.FromHex("#6D91BA"),
					Orientation = StackOrientation.Horizontal,
					Children = { title },
				};
			}
		}
	}
}