summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls/GalleryPages/MacOSTestGallery.cs
blob: 3b44683f8573f1d5c523d968ded861e45a578a2d (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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
using System;
using System.Collections.Generic;

namespace Xamarin.Forms.Controls
{
	public class MacOSTestGallery : ContentPage
	{
		public MacOSTestGallery()
		{
			mainDemoStack.Children.Add(MakeNewStackLayout());
			var items = new List<MyItem1>();
			for (int i = 0; i < 5000; i++)
			{
				items.Add(new MyItem1 { Reference = "Hello this is a big text " + i.ToString(), ShowButton = i % 2 == 0, Image = "bank.png" });
			}

			var header = new Label { Text = "HELLO HEADER ", FontSize = 40, BackgroundColor = Color.Pink };
			var lst4 = new ListView { Header = header, ItemTemplate = new DataTemplate(typeof(DemoViewCell)), BackgroundColor = Color.Yellow, HeightRequest = 300, RowHeight = 50, ItemsSource = items, };

			var lst = new ListView { ItemTemplate = new DataTemplate(typeof(DemoEntryCell)), BackgroundColor = Color.Yellow, HeightRequest = 300, RowHeight = 50, ItemsSource = items, };
			var lst1 = new ListView { ItemTemplate = new DataTemplate(typeof(DemoTextCell)), BackgroundColor = Color.Yellow, HeightRequest = 300, RowHeight = 50, ItemsSource = items, };
			var lst2 = new ListView { ItemTemplate = new DataTemplate(typeof(DemoSwitchCell)), BackgroundColor = Color.Yellow, HeightRequest = 300, RowHeight = 50, ItemsSource = items, };
			var lst3 = new ListView { ItemTemplate = new DataTemplate(typeof(DemoImageCell)), BackgroundColor = Color.Yellow, HeightRequest = 300, RowHeight = 50, ItemsSource = items, };

			var bigbUtton = new Button { WidthRequest = 200, HeightRequest = 300, Image = "bank.png" };

			var picker = new DatePicker();

			var timePicker = new TimePicker { Format = "T", Time = TimeSpan.FromHours(2) };

			var editor = new Editor { Text = "Edit this text on editor", HeightRequest = 100, TextColor = Color.Yellow, BackgroundColor = Color.Gray };

			var entry = new Entry { Placeholder = "Edit this text on entry", PlaceholderColor = Color.Pink, TextColor = Color.Yellow, BackgroundColor = Color.Green };

			var frame = new Frame { HasShadow = true, BackgroundColor = Color.Maroon, OutlineColor = Color.Lime, MinimumHeightRequest = 100 };


			var image = new Image { HeightRequest = 100, Source = "crimson.jpg" };

			var picker1 = new Picker { Title = "Select a team player", TextColor = Color.Pink, BackgroundColor = Color.Silver };
			picker1.Items.Add("Rui");
			picker1.Items.Add("Jason");
			picker1.Items.Add("Ez");
			picker1.Items.Add("Stephane");
			picker1.Items.Add("Samantha");
			picker1.Items.Add("Paul");

			picker1.SelectedIndex = 1;

			var progress = new ProgressBar { BackgroundColor = Color.Purple, Progress = 0.5, HeightRequest = 50 };

			picker1.SelectedIndexChanged += (sender, e) =>
			{
				entry.Text = $"Selected {picker1.Items[picker1.SelectedIndex]}";

				progress.Progress += 0.1;
			};

			var searchBar = new SearchBar { BackgroundColor = Color.Olive, TextColor = Color.Maroon, CancelButtonColor = Color.Pink };
			searchBar.Placeholder = "Please search";
			searchBar.PlaceholderColor = Color.Orange;
			searchBar.SearchButtonPressed += (sender, e) =>
			{
				searchBar.Text = "Search was pressed";
			};

			var slider = new Slider { BackgroundColor = Color.Lime, Value = 0.5 };

			slider.ValueChanged += (sender, e) =>
			{
				editor.Text = $"Slider value changed {slider.Value}";
			};

			var stepper = new Stepper { BackgroundColor = Color.Yellow, Maximum = 100, Minimum = 0, Value = 10, Increment = 0.5 };

			stepper.ValueChanged += (sender, e) =>
			{
				editor.Text = $"Stepper value changed {stepper.Value}";
			};

			var labal = new Label { Text = "This is a Switch" };
			var switchR = new Switch { BackgroundColor = Color.Fuchsia, IsToggled = true };
			switchR.Toggled += (sender, e) =>
			{
				entry.Text = $"switchR is toogle {switchR.IsToggled}";
			};
			var layoutSwitch = new StackLayout { Orientation = StackOrientation.Horizontal, BackgroundColor = Color.Green };
			layoutSwitch.Children.Add(labal);
			layoutSwitch.Children.Add(switchR);

			var webView = new WebView { HeightRequest = 200, Source = "http://google.pt" };

			var mainStck = new StackLayout
			{
				Spacing = 10,
				BackgroundColor = Color.Blue,
				VerticalOptions = LayoutOptions.Center,
				HorizontalOptions = LayoutOptions.Center,
				Children =
							{
								lst4,
								lst,
								lst1,
								lst2,
								lst3,
								webView,
								layoutSwitch,
								stepper,
								slider,
								searchBar,
								progress,
								picker1,
								image,
								frame,
								entry,
								editor,
								picker,
								timePicker,
								bigbUtton,
								new Button { Text = "Click Me", BackgroundColor = Color.Gray },
								new Button { Image = "bank.png", BackgroundColor = Color.Gray },
								CreateButton(new Button.ButtonContentLayout(Button.ButtonContentLayout.ImagePosition.Left, 10)),
								CreateButton(new Button.ButtonContentLayout(Button.ButtonContentLayout.ImagePosition.Top, 10)),
								CreateButton(new Button.ButtonContentLayout(Button.ButtonContentLayout.ImagePosition.Bottom, 10)),
								CreateButton(new Button.ButtonContentLayout(Button.ButtonContentLayout.ImagePosition.Right, 10)),
								mainDemoStack
							}
			};
			var lbl = new Label { Text = "Second label", TextColor = Color.White, VerticalTextAlignment = TextAlignment.Start, HorizontalTextAlignment = TextAlignment.Center };
			mainStck.Children.Add(new Label { Text = "HELLO XAMARIN FORMS MAC", TextColor = Color.White, HorizontalTextAlignment = TextAlignment.Center });
			mainStck.Children.Add(lbl);
			mainStck.Children.Add(new BoxView { Color = Color.Pink, HeightRequest = 200 });

			var scroller = new ScrollView { BackgroundColor = Color.Yellow, HorizontalOptions = LayoutOptions.Center };

			scroller.Scrolled += (sender, e) =>
			{
				lbl.Text = $"Current postion {scroller.ScrollY}";
			};

			scroller.Content = mainStck;

			var actv = new ActivityIndicator { BackgroundColor = Color.White, Color = Color.Fuchsia, IsRunning = true };
			mainStck.Children.Add(actv);

			bigbUtton.Clicked += async (sender, e) =>
			{
				await scroller.ScrollToAsync(actv, ScrollToPosition.Center, true);
				actv.Color = Color.Default;
			};

			Content = scroller;
		}

		public static ContentPage MacDemoContentPage()
		{
			return new MacOSTestGallery();
		}

		public static NavigationPage MacDemoNavigationPage()
		{
			var np = new NavigationPage(GetNewPage()) { BarTextColor = Color.Red, BarBackgroundColor = Color.Yellow };

			np.Pushed += (sender, e) => System.Diagnostics.Debug.WriteLine("Pushed + " + np.CurrentPage.Title);

			np.Popped += (sender, e) => System.Diagnostics.Debug.WriteLine("Popped");

			np.PoppedToRoot += (sender, e) => System.Diagnostics.Debug.WriteLine("Popped to root");

			return np;
		}

		public static TabbedPage MacDemoTabbedPage()
		{

			var btnGo = new Button { Text = "Change Title" };
			var btnGo1 = new Button { Text = "Change Icon" };

			var lyout = new StackLayout();
			lyout.Children.Add(btnGo);
			//lyout.Children.Add(btnGo1);

			var tp = new TabbedPage { BarTextColor = Color.Red, BarBackgroundColor = Color.Yellow };

			var master = new ContentPage { Icon = "bank.png", BackgroundColor = Color.Red, Title = "Master", Content = lyout };

			var detail = new ContentPage { Icon = "bank.png", BackgroundColor = Color.Blue, Title = "Detail", Content = new Label { Text = "This is Detail Page" } };

			tp.Children.Add(master);
			tp.Children.Add(detail);

			tp.CurrentPage = detail;

			tp.CurrentPageChanged += (sender, e) =>
			{
				System.Diagnostics.Debug.WriteLine(tp.CurrentPage.Title);
			};

			btnGo.Clicked += (sender, e) =>
			{
				tp.CurrentPage.Title = "Tile changed";
				tp.CurrentPage.Icon = null;
			};

			btnGo1.Clicked += (sender, e) =>
			{

			};
			return tp;
		}

		public static MasterDetailPage MacDemoMasterDetailPage()
		{
			var mdp = new MasterDetailPage();

			var master = new ContentPage { BackgroundColor = Color.Red, Title = "Master", Content = new Label { Text = "This is Master Page" } };

			var detail = new ContentPage { BackgroundColor = Color.Blue, Title = "Detail", Content = new Label { Text = "This is Detail Page" } };

			mdp.Master = master;
			mdp.Detail = detail;

			return mdp;
		}

		public static CarouselPage MacDemoCarouselPage()
		{

			var carouselPage = new CarouselPage { BackgroundColor = Color.Yellow };

			var btnGo = new Button { Text = "Goto To Page 1 " };
			var btnGo1 = new Button { Text = "Goto To Page 3 " };
			var stck = new StackLayout();
			stck.Children.Add(btnGo);
			stck.Children.Add(btnGo1);
			var page = new ContentPage { Title = "Page1", BackgroundColor = Color.Red, Content = new Label { Text = "Page 1 label", TextColor = Color.White, VerticalTextAlignment = TextAlignment.Start, HorizontalTextAlignment = TextAlignment.Center } };
			var page2 = new ContentPage { Title = "Page2", BackgroundColor = Color.Blue, Content = stck };
			var page3 = new ContentPage { Title = "Page3", BackgroundColor = Color.Green, Content = new Label { Text = "Page 3 label" } };

			carouselPage.Children.Add(page);
			carouselPage.Children.Add(page2);
			carouselPage.Children.Add(page3);

			carouselPage.CurrentPage = page2;

			btnGo.Clicked += (sender, e) =>
			{
				carouselPage.CurrentPage = page;
			};

			btnGo1.Clicked += (sender, e) =>
			{
				carouselPage.CurrentPage = page3;
			};

			carouselPage.CurrentPageChanged += (sender, e) =>
			{
				System.Diagnostics.Debug.WriteLine(carouselPage.CurrentPage.Title);
			};
			return carouselPage;
		}

		static int _pageID;

		static StackLayout mainDemoStack = new StackLayout { BackgroundColor = Color.Blue };

		static ContentPage GetNewPage()
		{
			var label = new Label { Text = $"Page {_pageID}" };
			var btnGo = new Button { Text = "Push Page" };
			var btnGo1 = new Button { Text = "Pop Page" };
			var lyout = new StackLayout();
			lyout.Children.Add(label);
			lyout.Children.Add(btnGo);
			lyout.Children.Add(btnGo1);

			btnGo.Clicked += async (sender, e) =>
			{
				_pageID++;
				await (lyout.Parent as Page).Navigation?.PushAsync(GetNewPage());

			};

			btnGo1.Clicked += async (sender, e) =>
			{
				_pageID--;
				await (lyout.Parent as Page).Navigation?.PopAsync();

			};

			return new ContentPage { Icon = "bank.png", BackgroundColor = _pageID % 2 == 0 ? Color.Blue : Color.Green, Title = label.Text, Content = lyout };
		}

		static StackLayout MakeNewStackLayout()
		{
			var count = 0;
			var stacklayout = new StackLayout { BackgroundColor = Color.Red };

			stacklayout.Children.Add(new Label { Text = $"HEllO {count}" });
			stacklayout.Children.Add(new Button
			{
				Text = "Change layout",
				Command = new Command(() =>
				{
					count += 2;
					stacklayout.Children.RemoveAt(2);

					var ll = new StackLayout();
					ll.Children.Add(new Label { Text = $"HEllO {count}" });
					ll.Children.Add(new Label { Text = $"HEllO {count + 1}" });
					stacklayout.Children.Add(ll);
				})
			});
			stacklayout.Children.Add(new Label { Text = $"HEllO {count + 1}" });
			count += 2;
			return stacklayout;
		}



		static Button CreateButton(Button.ButtonContentLayout layout)
		{
			return new Button
			{
				Text = "Click Me On Mac",
				Image = "bank.png",
				Font = Font.OfSize("Helvetica", 14),
				ContentLayout = layout,
				BackgroundColor = Color.Black,
				TextColor = Color.White
			};
		}

		class DemoSwitchCell : SwitchCell
		{
			public DemoSwitchCell()
			{
				SetBinding(TextProperty, new Binding("Reference"));
				SetBinding(OnProperty, new Binding("ShowButton"));
			}
		}

		class DemoImageCell : ImageCell
		{
			public DemoImageCell()
			{
				SetBinding(TextProperty, new Binding("Reference"));
				SetBinding(DetailProperty, new Binding("ShowButton"));
				SetBinding(ImageSourceProperty, new Binding("Image"));
			}
		}

		class DemoTextCell : TextCell
		{
			public DemoTextCell()
			{
				SetBinding(TextProperty, new Binding("Reference"));
				SetBinding(DetailProperty, new Binding("ShowButton"));
			}
		}

		class DemoEntryCell : EntryCell
		{
			public DemoEntryCell()
			{
				SetBinding(LabelProperty, new Binding("Reference"));
				SetBinding(TextProperty, new Binding("ShowButton"));
				LabelColor = Color.Red;
				Placeholder = "This is a entry cell";
			}
		}

		class DemoViewCell : ViewCell
		{
			public DemoViewCell()
			{
				var box = new Image { BackgroundColor = Color.Pink, WidthRequest = 100, HeightRequest = 40, Source = "bank.png" };
				var label = new Label { TextColor = Color.White };
				var labelDetail = new Label { TextColor = Color.White };

				label.SetBinding(Label.TextProperty, new Binding("Reference"));
				labelDetail.SetBinding(Label.TextProperty, new Binding("ShowButton"));

				var grid = new Grid { BackgroundColor = Color.Black };

				grid.Children.Add(box, 0, 1, 0, 1);
				grid.Children.Add(label, 1, 0);
				grid.Children.Add(labelDetail, 1, 1);

				View = grid;
			}
		}

		public class MyItem1
		{
			public string Reference { get; set; }
			public string Image { get; set; }
			public bool ShowButton { get; set; }
		}
	}
}