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

namespace Xamarin.Forms.Controls
{
	[Preserve (AllMembers = true)]
	public class TextCellTest {
		public object Text { get; set; }
		public object TextColor { get; set; }
		public object Detail { get; set; }
		public object DetailColor { get; set; }
	}

	public class TextCellListPage : ContentPage
	{
		public TextCellListPage ()
		{
			Title = "TextCell List Gallery - Legacy";

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

			var label = new Label { Text = "Not Selected" };

			var dataTemplate = new DataTemplate (typeof (TextCell));
			dataTemplate.SetBinding (TextCell.TextProperty, new Binding ("Text"));
			dataTemplate.SetBinding (TextCell.TextColorProperty, new Binding ("TextColor"));
			dataTemplate.SetBinding (TextCell.DetailProperty, new Binding ("Detail"));
			dataTemplate.SetBinding (TextCell.DetailColorProperty, new Binding ("DetailColor"));

			var listView = new ListView {
				ItemsSource = Enumerable.Range (0, 100).Select (i => new TextCellTest {
					Text = "Text " + i,
					TextColor = i % 2 == 0 ? Color.Red : Color.Blue,
					Detail = "Detail " + i,
					DetailColor = i % 2 == 0 ? Color.Red : Color.Blue
				}),
				ItemTemplate = dataTemplate
			};

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

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