-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathEntryOptionsPage.xaml.cs
More file actions
319 lines (286 loc) · 7.28 KB
/
EntryOptionsPage.xaml.cs
File metadata and controls
319 lines (286 loc) · 7.28 KB
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
using System;
using Microsoft.Maui.Controls;
namespace Maui.Controls.Sample;
public partial class EntryOptionsPage : ContentPage
{
private EntryViewModel _viewModel;
public EntryOptionsPage(EntryViewModel viewModel)
{
InitializeComponent();
_viewModel = viewModel;
BindingContext = _viewModel;
}
private async void ApplyButton_Clicked(object sender, EventArgs e)
{
await Navigation.PopAsync();
}
private void TextColorButton_Clicked(object sender, EventArgs e)
{
if (sender is Button button)
{
_viewModel.TextColor = button.AutomationId switch
{
"TextColorRed" => Colors.Red,
"TextColorBlue" => Colors.Blue,
_ => null
};
}
}
private void Entry_TextChanged(object sender, TextChangedEventArgs e)
{
if (BindingContext is EntryViewModel vm)
{
vm.Text = e.NewTextValue;
}
}
private void PlaceholderEntry_TextChanged(object sender, TextChangedEventArgs e)
{
if (BindingContext is EntryViewModel vm)
{
vm.Placeholder = e.NewTextValue;
}
}
private void PlaceholderColorButton_Clicked(object sender, EventArgs e)
{
if (sender is Button button)
{
_viewModel.PlaceholderColor = button.AutomationId switch
{
"PlaceholderColorRed" => Colors.Red,
"PlaceholderColorBlue" => Colors.Blue,
_ => null
};
}
}
private void ClearButtonVisibility_CheckedChanged(object sender, CheckedChangedEventArgs e)
{
if (sender == ClearButtonWhileEditing)
{
_viewModel.ClearButtonVisibility = ClearButtonVisibility.WhileEditing;
}
else if (sender == ClearButtonNever)
{
_viewModel.ClearButtonVisibility = ClearButtonVisibility.Never;
}
}
private void HorizontalAlignmentButton_Clicked(object sender, EventArgs e)
{
if (sender is Button button)
{
_viewModel.HorizontalTextAlignment = button.AutomationId switch
{
"HStart" => TextAlignment.Start,
"HCenter" => TextAlignment.Center,
"HEnd" => TextAlignment.End,
_ => _viewModel.HorizontalTextAlignment
};
}
}
private void VerticalAlignmentButton_Clicked(object sender, EventArgs e)
{
_viewModel.HeightRequest = 100;
if (sender is Button button)
{
_viewModel.VerticalTextAlignment = button.AutomationId switch
{
"VStart" => TextAlignment.Start,
"VCenter" => TextAlignment.Center,
"VEnd" => TextAlignment.End,
_ => _viewModel.VerticalTextAlignment
};
}
}
private void IsPasswordTrueOrFalse_Clicked(object sender, EventArgs e)
{
if (IsPasswordTrue.IsChecked)
{
_viewModel.IsPassword = true;
}
else if (IsPasswordFalse.IsChecked)
{
_viewModel.IsPassword = false;
}
}
private void ReturnTypeButton_Clicked(object sender, EventArgs e)
{
if (sender is Button button)
{
_viewModel.ReturnType = button.AutomationId switch
{
"Done" => ReturnType.Done,
"Next" => ReturnType.Next,
"Go" => ReturnType.Go,
"Search" => ReturnType.Search,
"Send" => ReturnType.Send,
"Default" => ReturnType.Default,
_ => _viewModel.ReturnType
};
}
}
private void MaxLengthEntry_TextChanged(object sender, TextChangedEventArgs e)
{
if (int.TryParse(MaxLengthEntry.Text, out int maxLength))
{
_viewModel.MaxLength = maxLength;
}
}
private void FontSizeEntry_TextChanged(object sender, TextChangedEventArgs e)
{
if (double.TryParse(FontSizeEntry.Text, out double fontSize))
{
_viewModel.FontSize = fontSize;
}
}
private void CharacterSpacing_TextChanged(object sender, TextChangedEventArgs e)
{
if (double.TryParse(CharacterSpacingEntry.Text, out double characterSpacing))
{
_viewModel.CharacterSpacing = characterSpacing;
}
}
private void IsReadOnlyTrueOrFalse_Clicked(object sender, EventArgs e)
{
if (IsReadOnlyTrue.IsChecked)
{
_viewModel.IsReadOnly = true;
}
else if (IsReadOnlyFalse.IsChecked)
{
_viewModel.IsReadOnly = false;
}
}
private void IsTextPredictionEnabledTrueOrFalse_Clicked(object sender, EventArgs e)
{
if (IsTextPredictionEnabledTrue.IsChecked)
{
_viewModel.IsTextPredictionEnabled = true;
}
else if (IsTextPredictionEnabledFalse.IsChecked)
{
_viewModel.IsTextPredictionEnabled = false;
}
}
private void IsSpellCheckEnabledTrueOrFalse_Clicked(object sender, EventArgs e)
{
if (IsSpellCheckEnabledTrue.IsChecked)
{
_viewModel.IsSpellCheckEnabled = true;
}
else if (IsSpellCheckEnabledFalse.IsChecked)
{
_viewModel.IsSpellCheckEnabled = false;
}
}
private void KeyboardButton_Clicked(object sender, EventArgs e)
{
if (sender is Button button)
{
_viewModel.Keyboard = button.AutomationId switch
{
"Default" => Keyboard.Default,
"Chat" => Keyboard.Chat,
"Email" => Keyboard.Email,
"Numeric" => Keyboard.Numeric,
"Telephone" => Keyboard.Telephone,
"Text" => Keyboard.Text,
"Url" => Keyboard.Url,
_ => _viewModel.Keyboard
};
}
}
private void FontFamilyEntry_TextChanged(object sender, TextChangedEventArgs e)
{
_viewModel.FontFamily = FontFamilyEntry.Text;
}
private void FlowDirection_CheckedChanged(object sender, CheckedChangedEventArgs e)
{
if (sender == FlowDirectionLeftToRight)
{
_viewModel.FlowDirection = FlowDirection.LeftToRight;
}
else if (sender == FlowDirectionRightToLeft)
{
_viewModel.FlowDirection = FlowDirection.RightToLeft;
}
}
private void IsVisibleTrueOrFalse_Clicked(object sender, EventArgs e)
{
if (IsVisibleTrue.IsChecked)
{
_viewModel.IsVisible = true;
}
else if (IsVisibleFalse.IsChecked)
{
_viewModel.IsVisible = false;
}
}
private void IsEnabledTrueOrFalse_Clicked(object sender, EventArgs e)
{
if (IsEnabledTrue.IsChecked)
{
_viewModel.IsEnabled = true;
}
else if (IsEnabledFalse.IsChecked)
{
_viewModel.IsEnabled = false;
}
}
private void TextTransform_CheckedChanged(object sender, CheckedChangedEventArgs e)
{
if (sender == TextTransformLowercase)
{
_viewModel.TextTransform = TextTransform.Lowercase;
}
else if (sender == TextTransformUppercase)
{
_viewModel.TextTransform = TextTransform.Uppercase;
}
else if (sender == TextTransformDefault)
{
_viewModel.TextTransform = TextTransform.Default;
}
}
private void BackgroundColorButton_Clicked(object sender, EventArgs e)
{
if (sender is Button button)
{
_viewModel.BackgroundColor = button.AutomationId switch
{
"BackgroundColorYellow" => Colors.Yellow,
"BackgroundColorLightBlue" => Colors.LightBlue,
_ => null
};
}
}
private void WidthRequestEntry_TextChanged(object sender, TextChangedEventArgs e)
{
if (double.TryParse(e.NewTextValue, out double widthRequest))
{
_viewModel.WidthRequest = widthRequest;
}
}
private void OpacityEntry_TextChanged(object sender, TextChangedEventArgs e)
{
if (double.TryParse(e.NewTextValue, out double opacity))
{
opacity = Math.Clamp(opacity, 0.0, 1.0);
_viewModel.Opacity = opacity;
}
}
private void HeightRequestEntry_TextChanged(object sender, TextChangedEventArgs e)
{
if (double.TryParse(e.NewTextValue, out double heightRequest))
{
_viewModel.HeightRequest = heightRequest;
}
}
private void FontAttributesCheckBox_CheckedChanged(object sender, CheckedChangedEventArgs e)
{
var attributes = FontAttributes.None;
if (FontAttributesBoldCheckBox.IsChecked)
attributes |= FontAttributes.Bold;
if (FontAttributesItalicCheckBox.IsChecked)
attributes |= FontAttributes.Italic;
_viewModel.FontAttributes = attributes;
}
}