summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls/GalleryPages/CellsGalleries/ImageCellListPage.cs
blob: 1f58a339bf3ab26bd2c711c401d560700f2729c3 (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
using System;
using System.Linq;
using System.Collections.Generic;

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

	public class ImageCellListPage : ContentPage
	{
	
		public ImageCellListPage ()
		{
			Title = "ImageCell List Gallery - Legacy";

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

			var dataTemplate = new DataTemplate (typeof (ImageCell));
			var stringToImageSourceConverter = new GenericValueConverter (
				obj => new FileImageSource {
					File = (string) obj
				}
				);
	
			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"));
			dataTemplate.SetBinding (ImageCell.ImageSourceProperty, new Binding ("Image", converter: stringToImageSourceConverter));

			Random rand = new Random(250);

			var albums = new [] {
				"crimsonsmall.jpg",
				"oasissmall.jpg",
				"cover1small.jpg"
			};

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

			var listView = new ListView {
				AutomationId = "ImageCellListView",
				ItemsSource = Enumerable.Range (0, 100).Select (i => new ImageCellTest {
					Text = "Text " + i,
					TextColor = i % 2 == 0 ? Color.Red : Color.Blue,
					Detail = "Detail " + i,
					DetailColor = i % 2 == 0 ? Color.Red : Color.Blue,
					Image = albums[rand.Next(0,3)]
				}),
				ItemTemplate = dataTemplate
			};

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

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

		}
	}

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

			var dataTemplate = new DataTemplate (typeof (ImageCell));
			var stringToImageSourceConverter = new GenericValueConverter (
				obj => new UriImageSource() {
					Uri = new Uri ((string) obj)
				});

			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"));
			dataTemplate.SetBinding (ImageCell.ImageSourceProperty,
				new Binding ("Image", converter: stringToImageSourceConverter));

			var albums = new List<string> ();
			for (int i = 0; i < 30; i++) {
				albums.Add (string.Format ("http://cdn.instructables.com/FCP/9TOJ/GCJ0ZQV5/FCP9TOJGCJ0ZQV5.MEDIUM.jpg?ticks={0}",i ));
			}


			var random = new Random();
			var label = new Label { Text = "I have not been selected" };

			var listView = new ListView {
				AutomationId = "ImageUrlCellListView",
				ItemsSource = Enumerable.Range (0, 300).Select (i => new ImageCellTest {
					Text = "Text " + i,
					TextColor = i % 2 == 0 ? Color.Red : Color.Blue,
					Detail = "Detail " + i,
					DetailColor = i % 2 == 0 ? Color.Red : Color.Blue,
					Image = albums [random.Next (0, albums.Count - 1)]
				}),
				ItemTemplate = dataTemplate
			};

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

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

		}
	}
}