15 private readonly Layout.Page page;
21 this.form = this.page.
Form;
24 public string Label => this.page.Label;
26 public bool HasLabel => !
string.IsNullOrEmpty(this.page.Label);
28 public View Content => this.BuildContent(this.page.Elements);
30 private VerticalStackLayout BuildContent(Layout.LayoutElement[] Elements)
32 VerticalStackLayout Result =
new VerticalStackLayout();
34 foreach (Layout.LayoutElement Element in Elements)
36 if (this.BuildContent(Element) is View view)
37 Result.Children.Add(view);
43 private object? BuildContent(Layout.LayoutElement Element)
45 if (Element is Layout.FieldReference FieldRef)
53 HorizontalStackLayout Layout = [];
55 CheckBox CheckBox =
new()
60 VerticalOptions = LayoutOptions.Center,
61 BackgroundColor = BackgroundColor(
Field)
64 CheckBox.CheckedChanged += this.CheckBox_CheckedChanged;
66 Layout.Children.Add(CheckBox);
67 Layout.Children.Add(
new Label()
71 LineBreakMode = LineBreakMode.WordWrap,
72 VerticalOptions = LayoutOptions.Center
83 LineBreakMode = LineBreakMode.WordWrap
88 VerticalStackLayout Layout = [];
90 Layout.Children.Add(
new Label()
94 LineBreakMode = LineBreakMode.WordWrap
102 BackgroundColor = BackgroundColor(
Field),
106 Entry.TextChanged += this.Entry_TextChanged;
108 Layout.Children.Add(Entry);
114 VerticalStackLayout Layout = [];
116 Layout.Children.Add(
new Label()
120 LineBreakMode = LineBreakMode.WordWrap
123 Editor Editor =
new()
128 BackgroundColor = BackgroundColor(
Field)
131 Editor.TextChanged += this.Editor_TextChanged;
133 Layout.Children.Add(Editor);
139 VerticalStackLayout Layout = [];
141 Layout.Children.Add(
new Label()
145 LineBreakMode = LineBreakMode.WordWrap
148 Picker Picker =
new()
153 BackgroundColor = BackgroundColor(
Field)
156 if (
Field?.Options is not
null)
158 foreach (KeyValuePair<string, string> Option
in Field.
Options)
159 Picker.Items.Add(Option.Key);
163 Picker.SelectedIndexChanged += this.Picker_SelectedIndexChanged;
165 Layout.Children.Add(Picker);
171 VerticalStackLayout Layout = [];
173 Layout.Children.Add(
new Label()
177 LineBreakMode = LineBreakMode.WordWrap
182 Dictionary<string, bool> Selected = [];
190 foreach (KeyValuePair<string, string> Option
in Field.
Options)
192 HorizontalStackLayout Layout2 = [];
194 CheckBox CheckBox =
new()
196 IsChecked = Selected.ContainsKey(Option.Value),
198 StyleId = Field.Var +
" | " + Option.Value,
199 VerticalOptions = LayoutOptions.Center,
200 BackgroundColor = BackgroundColor(
Field)
203 CheckBox.CheckedChanged += this.MultiCheckBox_CheckedChanged;
205 Layout2.Children.Add(CheckBox);
206 Layout2.Children.Add(
new Label()
210 LineBreakMode = LineBreakMode.WordWrap,
211 VerticalOptions = LayoutOptions.Center
214 Layout.Children.Add(Layout2);
226 VerticalStackLayout Layout = [];
228 Layout.Children.Add(
new Label()
232 LineBreakMode = LineBreakMode.WordWrap
238 Source = ImageSource.FromStream(() =>
new MemoryStream(
Media.
Binary));
239 else if (!
string.IsNullOrEmpty(
Media.
URL) && Uri.TryCreate(
Media.
URL, UriKind.Absolute, out Uri? ParsedUrl))
240 Source = ImageSource.FromUri(ParsedUrl);
244 if (Source is not
null)
249 HorizontalOptions = LayoutOptions.Center,
250 VerticalOptions = LayoutOptions.Start
253 Layout.Children.Add(Image);
264 else if (Element is Layout.Section
Section)
266 VerticalStackLayout Layout = [];
270 Layout.Children.Add(
new Label()
274 LineBreakMode = LineBreakMode.WordWrap
280 object? Content = this.BuildContent(Element2);
282 if (Content is View View)
283 Layout.Children.Add(View);
289 Padding =
new Thickness(10),
296 else if (Element is Layout.TextElement Text)
302 LineBreakMode = LineBreakMode.WordWrap
309 private static Color? BackgroundColor(
Field F)
319 private void CheckBox_CheckedChanged(
object? sender, CheckedChangedEventArgs e)
321 if (sender is not CheckBox CheckBox)
324 string Var = CheckBox.StyleId;
331 CheckBox.BackgroundColor = BackgroundColor(
Field);
333 this.model.ValidateForm();
336 private void Entry_TextChanged(
object? sender, TextChangedEventArgs e)
338 if (sender is not Entry Entry)
341 string Var = Entry.StyleId;
348 Entry.BackgroundColor = BackgroundColor(
Field);
350 this.model.ValidateForm();
353 private void Editor_TextChanged(
object? sender, TextChangedEventArgs e)
355 if (sender is not Editor Editor)
358 string Var = Editor.StyleId;
365 Editor.BackgroundColor = BackgroundColor(
Field);
367 this.model.ValidateForm();
370 private void Picker_SelectedIndexChanged(
object? sender, EventArgs e)
372 if (sender is not Picker Picker)
375 string Var = Picker.StyleId;
380 string s = Picker.SelectedItem?.ToString() ??
string.Empty;
384 foreach (KeyValuePair<string, string> P
in Field.
Options)
396 Picker.BackgroundColor = BackgroundColor(
Field);
398 this.model.ValidateForm();
401 private void MultiCheckBox_CheckedChanged(
object? sender, CheckedChangedEventArgs e)
403 if (sender is not CheckBox CheckBox)
406 string Var = CheckBox.StyleId;
407 int i = Var.IndexOf(
" | ", StringComparison.InvariantCultureIgnoreCase);
411 string Value = Var[(i + 3)..];
418 List<string> Values = [];
424 i = Values.IndexOf(Value);
429 Values.Remove(Value);
433 CheckBox.BackgroundColor = BackgroundColor(
Field);
435 this.model.ValidateForm();
Static class that gives access to app-specific themed colors
static Color DisabledFilledButtonBackground
DisabledFilledButton background color.
static Color PrimaryForeground
Primary foreground color.
static Color ErrorBackground
Error Background Color.
Static class that gives access to app-specific styles
static Style SectionTitleLabel
Style of section title labels
static Style InfoLabel
Style of information labels
static Style KeyLabel
Style of key labels
The view model to bind to for when displaying the calculator.
Helps with parsing of commong data types.
static string Encode(bool x)
Encodes a Boolean for use in XML and other formats.
static bool TryParse(string s, out double Value)
Tries to decode a string encoded double.
Class managing a page in a data form layout.