5using Microsoft.Maui.Controls.Shapes;
16 private readonly Layout.Page page;
22 this.form = this.page.
Form;
25 public string Label => this.page.Label;
27 public bool HasLabel => !
string.IsNullOrEmpty(this.page.Label);
29 public View Content => this.BuildContent(this.page.Elements);
31 private VerticalStackLayout BuildContent(Layout.LayoutElement[] Elements)
33 VerticalStackLayout Result =
new VerticalStackLayout();
35 foreach (Layout.LayoutElement Element in Elements)
37 if (this.BuildContent(Element) is View view)
38 Result.Children.Add(view);
44 private object? BuildContent(Layout.LayoutElement Element)
46 if (Element is Layout.FieldReference FieldRef)
54 HorizontalStackLayout Layout = [];
56 CheckBox CheckBox =
new()
61 VerticalOptions = LayoutOptions.Center,
62 BackgroundColor = BackgroundColor(
Field)
65 CheckBox.CheckedChanged += this.CheckBox_CheckedChanged;
67 Layout.Children.Add(CheckBox);
68 Layout.Children.Add(
new Label()
72 LineBreakMode = LineBreakMode.WordWrap,
73 VerticalOptions = LayoutOptions.Center
84 LineBreakMode = LineBreakMode.WordWrap
89 VerticalStackLayout Layout = [];
91 Layout.Children.Add(
new Label()
95 LineBreakMode = LineBreakMode.WordWrap
103 BackgroundColor = BackgroundColor(
Field),
107 Entry.TextChanged += this.Entry_TextChanged;
109 Layout.Children.Add(Entry);
115 VerticalStackLayout Layout = [];
117 Layout.Children.Add(
new Label()
121 LineBreakMode = LineBreakMode.WordWrap
124 Editor Editor =
new()
129 BackgroundColor = BackgroundColor(
Field)
132 Editor.TextChanged += this.Editor_TextChanged;
134 Layout.Children.Add(Editor);
140 VerticalStackLayout Layout = [];
142 Layout.Children.Add(
new Label()
146 LineBreakMode = LineBreakMode.WordWrap
149 Picker Picker =
new()
154 BackgroundColor = BackgroundColor(
Field)
157 if (
Field?.Options is not
null)
159 foreach (KeyValuePair<string, string> Option
in Field.
Options)
160 Picker.Items.Add(Option.Key);
164 Picker.SelectedIndexChanged += this.Picker_SelectedIndexChanged;
166 Layout.Children.Add(Picker);
172 VerticalStackLayout Layout = [];
174 Layout.Children.Add(
new Label()
178 LineBreakMode = LineBreakMode.WordWrap
183 Dictionary<string, bool> Selected = [];
191 foreach (KeyValuePair<string, string> Option
in Field.
Options)
193 HorizontalStackLayout Layout2 = [];
195 CheckBox CheckBox =
new()
197 IsChecked = Selected.ContainsKey(Option.Value),
199 StyleId = Field.Var +
" | " + Option.Value,
200 VerticalOptions = LayoutOptions.Center,
201 BackgroundColor = BackgroundColor(
Field)
204 CheckBox.CheckedChanged += this.MultiCheckBox_CheckedChanged;
206 Layout2.Children.Add(CheckBox);
207 Layout2.Children.Add(
new Label()
211 LineBreakMode = LineBreakMode.WordWrap,
212 VerticalOptions = LayoutOptions.Center
215 Layout.Children.Add(Layout2);
227 VerticalStackLayout Layout = [];
229 Layout.Children.Add(
new Label()
233 LineBreakMode = LineBreakMode.WordWrap
239 Source = ImageSource.FromStream(() =>
new MemoryStream(
Media.
Binary));
240 else if (!
string.IsNullOrEmpty(
Media.
URL) && Uri.TryCreate(
Media.
URL, UriKind.Absolute, out Uri? ParsedUrl))
241 Source = ImageSource.FromUri(ParsedUrl);
245 if (Source is not
null)
250 HorizontalOptions = LayoutOptions.Center,
251 VerticalOptions = LayoutOptions.Start
254 Layout.Children.Add(Image);
265 else if (Element is Layout.Section
Section)
267 VerticalStackLayout Layout = [];
271 Layout.Children.Add(
new Label()
275 LineBreakMode = LineBreakMode.WordWrap
281 object? Content = this.BuildContent(Element2);
283 if (Content is View View)
284 Layout.Children.Add(View);
290 Padding =
new Thickness(10),
291 StrokeShape =
new RoundRectangle
300 else if (Element is Layout.TextElement Text)
306 LineBreakMode = LineBreakMode.WordWrap
313 private static Color? BackgroundColor(
Field F)
323 private void CheckBox_CheckedChanged(
object? sender, CheckedChangedEventArgs e)
325 if (sender is not CheckBox CheckBox)
328 string Var = CheckBox.StyleId;
335 CheckBox.BackgroundColor = BackgroundColor(
Field);
337 this.model.ValidateForm();
340 private void Entry_TextChanged(
object? sender, TextChangedEventArgs e)
342 if (sender is not Entry Entry)
345 string Var = Entry.StyleId;
352 Entry.BackgroundColor = BackgroundColor(
Field);
354 this.model.ValidateForm();
357 private void Editor_TextChanged(
object? sender, TextChangedEventArgs e)
359 if (sender is not Editor Editor)
362 string Var = Editor.StyleId;
369 Editor.BackgroundColor = BackgroundColor(
Field);
371 this.model.ValidateForm();
374 private void Picker_SelectedIndexChanged(
object? sender, EventArgs e)
376 if (sender is not Picker Picker)
379 string Var = Picker.StyleId;
384 string s = Picker.SelectedItem?.ToString() ??
string.Empty;
388 foreach (KeyValuePair<string, string> P
in Field.
Options)
400 Picker.BackgroundColor = BackgroundColor(
Field);
402 this.model.ValidateForm();
405 private void MultiCheckBox_CheckedChanged(
object? sender, CheckedChangedEventArgs e)
407 if (sender is not CheckBox CheckBox)
410 string Var = CheckBox.StyleId;
411 int i = Var.IndexOf(
" | ", StringComparison.InvariantCultureIgnoreCase);
415 string Value = Var[(i + 3)..];
422 List<string> Values = [];
428 i = Values.IndexOf(Value);
433 Values.Remove(Value);
437 CheckBox.BackgroundColor = BackgroundColor(
Field);
439 this.model.ValidateForm();
Static class that gives access to app-specific themed colors. All colors are fetched directly from th...
static Color PrimaryForeground
Primary foreground color.
static Color ErrorBackground
Error Background Color.
static Color ButtonUniversalbgInactiveWL
DisabledFilledButton 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.