summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue1590.cs
blob: 2e1c70c703435ff342486d0d9a7ef881d40ae7da (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
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms.CustomAttributes;

namespace Xamarin.Forms.Controls.TestCasesPages
{
	[Preserve (AllMembers=true)]
	[Issue (IssueTracker.Github, 1590, "ListView.IsGroupingEnabled results ins ArguementOutOfRangeException", PlatformAffected.Android)]
	public class Issue1590 : ContentPage
	{
		ListView _listView;

		public Issue1590()
		{
			var vm = new RootPageViewModel();
			Content = BuildListView(vm);
		}

		StackLayout BuildListView(RootPageViewModel viewModel)
		{
			var headerTemplate = new DataTemplate(typeof(ModuleMediaListHeaderTemplate));
			headerTemplate.CreateContent();

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

			_listView = new ListView
			{
				ItemsSource = viewModel.MediaSections,
				IsGroupingEnabled = true,
				GroupDisplayBinding = new Binding("SectionName"),
				HasUnevenRows = false,
				GroupHeaderTemplate = headerTemplate,
				ItemTemplate = itemTemplate
			};

			return new StackLayout { Children = { _listView } };
		}
	}

	[Preserve (AllMembers=true)]
	public class RootPageViewModel
	{
		public IEnumerable MediaSections
		{
			get
			{
				var titles = new[] {"First", "Second", "Third", "Forth", "Fifth"};

				return titles.Select(section => new MediaListSection(section)
				{
					new FooViewModel {Title = "Foo", Description = "description for foo"}, 
					new FooViewModel {Title = "Bar", Description = "description for bar"}, 
					new FooViewModel {Title = "Baz", Description = "description for baz"}, 
					new FooViewModel {Title = "Fiz", Description = "description for fiz"}, 
					new FooViewModel {Title = "Buz", Description = "description for buz"},
				}).ToList();
			}
		}
	}

	[Preserve (AllMembers=true)]
	public class MediaListSection : ObservableCollection<FooViewModel>
	{
		public string SectionName { get; private set; }

		public MediaListSection(string sectionName)
		{
			SectionName = sectionName;
		}
	}

	[Preserve (AllMembers=true)]
	public class FooViewModel
	{
		public string Title { get; set; }
		public string Description { get; set; }
	}

	[Preserve (AllMembers=true)]
	public class ModuleMediaListItemTemplate : ViewCell
	{
		public ModuleMediaListItemTemplate()
		{
			var title = new Label { YAlign = TextAlignment.Center };
			title.SetBinding(Label.TextProperty, new Binding("Title", BindingMode.OneWay));

			var description = new Label { YAlign = TextAlignment.Center };
			description.SetBinding(Label.TextProperty, new Binding("Description", BindingMode.OneWay));

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

	[Preserve (AllMembers=true)]
	public class ModuleMediaListHeaderTemplate : ViewCell
	{
		public ModuleMediaListHeaderTemplate()
		{
			var title = new Label { TextColor = Color.White, YAlign = TextAlignment.Center };
			title.SetBinding(Label.TextProperty, new Binding("SectionName", BindingMode.OneWay));

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