summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls/ControlGalleryPages/CellForceUpdateSizeGalleryPage.cs
blob: 6e64b0d7237bd31319173c15ded5a4beb431fc6a (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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
using System;
using System.Collections.Generic;
using System.Linq;
using Xamarin.Forms.Internals;

namespace Xamarin.Forms.Controls
{
	[Preserve (AllMembers = true)]
	public class CellForceUpdateSizeGalleryPage : TabbedPage
	{
		public class ViewCellPage : ContentPage
		{
			[Preserve (AllMembers = true)]
			public class MyViewCell : ViewCell
			{
				public MyViewCell ()
				{
					var image = new Image {
						Source = ImageSource.FromFile ("crimson.jpg"),
						BackgroundColor = Color.Gray,
						HeightRequest = 50,
						VerticalOptions = LayoutOptions.Fill,
						HorizontalOptions = LayoutOptions.Fill
					};

					var button = new Button { Text = "+" };
					button.Clicked += (object sender, EventArgs e) =>
					{
						image.HeightRequest = image.Height + 100;
						ForceUpdateSize ();
					};

					Tapped += (object sender, EventArgs e) =>
					{
						image.HeightRequest = image.Height - 100;
						ForceUpdateSize ();
					};

					View = new StackLayout { Orientation = StackOrientation.Horizontal, Children = { image, button } };
				}
			}

			public ViewCellPage ()
			{
				var listview = new ListView {
					HasUnevenRows = true,
				};
				var items = Enumerable.Range (0, 10);
				listview.ItemsSource = items;
				listview.ItemTemplate = new DataTemplate (typeof (MyViewCell));
				Content = listview;
				Title = "View Cell";
			}
		}

		public class ImageCellPage : ContentPage
		{
			[Preserve (AllMembers = true)]
			public class MyImageCell : ImageCell
			{
				public MyImageCell ()
				{
					ImageSource = ImageSource.FromFile ("crimson.jpg");
					Height = 20;
					Command = new Command (() =>
					{
						Height += 20;
						ForceUpdateSize ();
					});
				}
			}
			public ImageCellPage ()
			{
				var listview = new ListView {
					HasUnevenRows = true,
				};
				var items = Enumerable.Range (0, 10);
				listview.ItemsSource = items;
				listview.ItemTemplate = new DataTemplate (typeof (MyImageCell));
				Content = listview;
				Title = "Image Cell";
			}
		}

		public class TextCellPage : ContentPage
		{
			[Preserve (AllMembers = true)]
			public class MyTextCell : TextCell
			{
				public MyTextCell ()
				{
					Text = "I am a TextCell, short and stout.";
					Height = 20;
					Command = new Command (() =>
					{
						Height += 20;
						ForceUpdateSize ();
					});
				}
			}

			public TextCellPage ()
			{
				var listview = new ListView {
					HasUnevenRows = true,
				};
				var items = Enumerable.Range (0, 10);
				listview.ItemsSource = items;
				listview.ItemTemplate = new DataTemplate (typeof (MyTextCell));
				Content = listview;
				Title = "Text Cell";
			}
		}

		public class EntryCellPage : ContentPage
		{
			[Preserve (AllMembers = true)]
			public class MyEntryCell : EntryCell
			{
				public MyEntryCell ()
				{
					Text = "I am an EntryCell, short and stout.";
					Height = 20;
					Tapped += (object sender, EventArgs e) =>
					{
						Height += 20;
						ForceUpdateSize ();
					};
					Completed += (object sender, EventArgs e) =>
					{
						Height -= 20;
						ForceUpdateSize ();
					};
				}
			}

			public EntryCellPage ()
			{
				var listview = new ListView {
					HasUnevenRows = true,
				};
				var items = Enumerable.Range (0, 10);
				listview.ItemsSource = items;
				listview.ItemTemplate = new DataTemplate (typeof (MyEntryCell));
				Content = listview;
				Title = "Entry Cell";
			}
		}

		public class SwitchCellPage : ContentPage
		{
			[Preserve (AllMembers = true)]
			public class MySwitchCell : SwitchCell
			{
				public MySwitchCell ()
				{
					Text = "I am a SwitchCell, short and stout.";
					Height = 20;
					Tapped += (object sender, EventArgs e) =>
					{
						Height += 20;
						ForceUpdateSize ();
					};
					OnChanged += (object sender, ToggledEventArgs e) =>
					{
						Height -= 20;
						ForceUpdateSize ();
					};
				}
			}

			public SwitchCellPage ()
			{
				var listview = new ListView {
					HasUnevenRows = true,
				};
				var items = Enumerable.Range (0, 10);
				listview.ItemsSource = items;
				listview.ItemTemplate = new DataTemplate (typeof (MySwitchCell));
				Content = listview;
				Title = "Switch Cell";
			}
		}

		public CellForceUpdateSizeGalleryPage ()
		{
			Children.Add (new ViewCellPage ());
			Children.Add (new ImageCellPage ());
			Children.Add (new TextCellPage ());
			Children.Add (new EntryCellPage ());
			Children.Add (new SwitchCellPage ());
		}
	}
}