summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls/GalleryPages/CellsGalleries/SwitchCellListPage.cs
blob: c2502339274bd8adfa2d1a9943ba35206be4162f (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
using System.Linq;

namespace Xamarin.Forms.Controls
{
	[Preserve (AllMembers = true)]
	public class SwitchCellItem 
	{
		public string Label { get; set; }
		public bool SwitchOn { get; set; }
	}

	public class SwitchCellListPage : ContentPage
	{
		public SwitchCellListPage ()
		{
			Title = "SwitchCell List Gallery - Legacy";

			Device.OnPlatform (iOS: () => {
				if (Device.Idiom == TargetIdiom.Tablet) {
					Padding = new Thickness (0, 0, 0, 60);
				}
			});

			var dataTemplate = new DataTemplate (typeof (SwitchCell)) {
				Bindings = {
					{SwitchCell.TextProperty, new Binding ("Label")},
					{SwitchCell.OnProperty, new Binding ("SwitchOn")},
				}
			};

			var label = new Label { Text = "I have not been selected" };

			var listView = new ListView {
				ItemsSource = Enumerable.Range (0, 100).Select (i => new SwitchCellItem {
					Label = "Label " + i,
					SwitchOn =  i % 2 == 0 ? false : true,
				}),
				ItemTemplate = dataTemplate
			};

			listView.ItemSelected += (sender, args) => label.Text = "I was selected.";

			Content = new StackLayout { Children = { label, listView } };
		}

	}
}