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

namespace Xamarin.Forms.Controls.Issues
{
	[Preserve(AllMembers = true)]
	[Issue(IssueTracker.Bugzilla, 39802, "Gap between ListView cells even if SeparatorVisablity is set to none ", PlatformAffected.iOS)]
	public class Bugzilla39802 : TestContentPage // or TestMasterDetailPage, etc ...
	{
		protected override void Init()
		{
			BackgroundColor = Color.Yellow;

			var list = new ObservableCollection<GroupedData>();

			for (int i = 1; i <= 2; i++)
			{
				var group = new GroupedData { GroupName = $"Group #{i}" };

				for (int j = 1; j < 30; j++)
				{
					var item = new MyItem { Title = $"Item: #{i}-{j}", Color = (j % 2 == 0) ? Color.Blue : Color.Red };

					group.Add(item);
				}
				list.Add(group);
			}

			ListItems = list;

			BindingContext = this;
			var lst = new ListView(ListViewCachingStrategy.RecycleElement)
			{
				BackgroundColor = Color.Transparent,
				ItemTemplate = new DataTemplate(typeof(ItemTemplate)),
				GroupHeaderTemplate = new DataTemplate(typeof(GroupHeaderTemplate)),
				IsGroupingEnabled = true,
				GroupDisplayBinding = new Binding(nameof(GroupedData.GroupName)),
				GroupShortNameBinding = new Binding(nameof(GroupedData.GroupName)),
			};
			lst.SeparatorVisibility = SeparatorVisibility.None;
			lst.SeparatorColor = Color.Green;
			lst.SetBinding(ListView.ItemsSourceProperty, nameof(ListItems));
			Content = lst;
		}

		public class ItemTemplate : ViewCell
		{
			public ItemTemplate()
			{
				var stk = new StackLayout
				{
					Padding = new Thickness(15, 0, 0, 0)
				};
				stk.SetBinding(VisualElement.BackgroundColorProperty, nameof(MyItem.Color));
				var lbl = new Label
				{
					TextColor = Color.Yellow,
					VerticalOptions = LayoutOptions.CenterAndExpand
				};
				lbl.SetBinding(Label.TextProperty, nameof(MyItem.Title));
				stk.Children.Add(lbl);
				View = stk;
			}
		}
		public class GroupHeaderTemplate : ViewCell
		{
			public GroupHeaderTemplate()
			{
				var title = new Label { TextColor = Color.White, FontSize = 16 };
				title.SetBinding(Label.TextProperty, new Binding(nameof(GroupedData.GroupName), BindingMode.OneWay));

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

		public ObservableCollection<GroupedData> ListItems { get; set; }
		public class MyItem
		{
			public string Title { get; set; }

			public Color Color { get; set; }
		}

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