summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls/GalleryPages/EditorGallery.cs
blob: fde032360f0574da1ca3cbca609ddec298e97f61 (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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Xamarin.Forms.Controls
{
	public class EditorGallery : ContentPage
	{
		public EditorGallery ()
		{
			var cellTemplate = new DataTemplate (typeof (TextCell));
			cellTemplate.SetBinding (TextCell.TextProperty, new Binding ("Title"));

			var list = new ListView {
				ItemsSource = new ContentPage [] {
					new EditorGalleryPage ("Default Keyboard", Keyboard.Default),
					new EditorGalleryPage ("Chat Keyboard", Keyboard.Chat),
					new EditorGalleryPage ("Text Keyboard", Keyboard.Text),
					new EditorGalleryPage ("Url Keyboard", Keyboard.Url),
					new EditorGalleryPage ("Numeric Keyboard", Keyboard.Numeric),
					new EditableEditorPage ("Enabled", true),
					new EditableEditorPage ("Disabled", false),

				},
				ItemTemplate = cellTemplate
			};

			list.ItemSelected += (sender, arg) => {
				if (list.SelectedItem != null) {
					Navigation.PushAsync ((ContentPage)list.SelectedItem);
					list.SelectedItem = null;
				}
			};

			Content = list;
		}
	}

	internal class EditableEditorPage : ContentPage
	{
		public EditableEditorPage (string title, bool enabled)
		{
			Title = "Editable " + enabled.ToString ();
			Padding = new Thickness (20);
			var editor = new Editor {
				Text = Title,
				IsEnabled = enabled,
				HeightRequest = 75,
			};

			var disableButton = new Button {
				Text = "Disable Editor",
			};

			var enableButton = new Button {
				Text = "Enable Editor",
			};

			disableButton.Clicked += (object sender, EventArgs e) => {
				editor.IsEnabled = false;
			};

			enableButton.Clicked += (object sender, EventArgs e) => {
				editor.IsEnabled = true;
			};

			Content = new StackLayout {
				Children = { editor, disableButton, enableButton, }
			};
		}
	}

	public class EditorGalleryPage : ContentPage
	{
		public EditorGalleryPage (string title, Keyboard keyboard)
		{
			Title = title;
			BackgroundColor = Color.Red;
			Padding = new Thickness (20);

			var label = new Label {
				Text = "Nothing entered"
			};

			var label2 = new Label {
				Text = ""
			};

			var editor = new Editor {
				HeightRequest = 75,
				Keyboard = keyboard,
				Text = "PlaceHolder",
			};
					
			editor.Completed += (sender, e) => {
				label.Text = "Entered : " + editor.Text;
			};

			editor.TextChanged += (sender, e) => {
				label2.Text += "x";
			};

			var unfocus = new Button {
				Text = "Unfocus",
			};

			var focus = new Button {
				Text = "Focus",
			};
				
			unfocus.Clicked += (sender, e) => {
				editor.Unfocus();
			};

			focus.Clicked += (sender, e) => {
				editor.Focus();
			};

			Content = new StackLayout {
				Children = {
					label,
					label2,
					editor,
					focus,
					unfocus,
				}
			};
		}
	}
}