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

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";

			if (Device.RuntimePlatform == Device.iOS && 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 } };
		}

	}
}