1using ICSharpCode.AvalonEdit.Highlighting;
2using ICSharpCode.AvalonEdit.Highlighting.Xshd;
4using System.Collections.Generic;
6using System.Threading.Tasks;
8using System.Windows.Controls;
9using System.Windows.Documents;
10using System.Windows.Media;
11using System.Windows.Media.Imaging;
30 private FrameworkElement makeVisible =
null;
31 private bool empty =
true;
42 public bool Empty => this.empty;
54 Panel Container = Result.DialogPanel;
55 TabControl TabControl =
null;
57 StackPanel StackPanel;
58 ScrollViewer ScrollViewer;
64 TabControl =
new TabControl();
65 Result.DialogPanel.Children.Add(TabControl);
66 DockPanel.SetDock(TabControl, Dock.Top);
70 ScrollViewer =
new ScrollViewer()
72 VerticalScrollBarVisibility = ScrollBarVisibility.Auto
75 Result.DialogPanel.Children.Add(ScrollViewer);
76 DockPanel.SetDock(ScrollViewer, Dock.Top);
78 StackPanel =
new StackPanel()
80 Margin =
new Thickness(10, 10, 10, 10),
83 ScrollViewer.Content = StackPanel;
84 Container = StackPanel;
87 foreach (Networking.XMPP.DataForms.Layout.Page
Page in Form.
Pages)
89 if (!(TabControl is
null))
91 TabItem =
new TabItem()
96 TabControl.Items.Add(TabItem);
98 ScrollViewer =
new ScrollViewer()
100 VerticalScrollBarVisibility = ScrollBarVisibility.Auto
103 TabItem.Content = ScrollViewer;
105 StackPanel =
new StackPanel()
107 Margin =
new Thickness(10, 10, 10, 10)
110 ScrollViewer.Content = StackPanel;
111 Container = StackPanel;
120 TextBlock TextBlock =
new TextBlock()
122 TextWrapping = TextWrapping.Wrap,
123 Margin =
new Thickness(0, 5, 0, 5),
127 Container.Children.Add(TextBlock);
128 Result.empty =
false;
134 Control = await Result.Layout(Container, Element, Form);
139 if (!(TabControl is
null) && TabControl.Items.Count == 1)
145 Result.CheckOkButtonEnabled();
157 else if (Element is Networking.XMPP.DataForms.Layout.TextElement
TextElement)
162 else if (Element is Networking.XMPP.DataForms.Layout.Section
Section)
165 return await this.Layout(Container,
Section, Form);
176 private async Task<Control> Layout(Panel Container, Networking.XMPP.DataForms.Layout.Section
Section,
DataForm Form)
178 GroupBox GroupBox =
new GroupBox();
179 Container.Children.Add(GroupBox);
181 GroupBox.Margin =
new Thickness(5, 5, 5, 5);
183 StackPanel StackPanel =
new StackPanel();
184 GroupBox.Content = StackPanel;
185 StackPanel.Margin =
new Thickness(5, 5, 5, 5);
187 Control First =
null;
192 Control = await this.Layout(StackPanel, Element, Form);
200 private void Layout(Panel Container, Networking.XMPP.DataForms.Layout.TextElement
TextElement,
DataForm _)
202 TextBlock TextBlock =
new TextBlock()
204 TextWrapping = TextWrapping.Wrap,
205 Margin =
new Thickness(0, 0, 0, 5),
206 Text = TextElement.Text
209 Container.Children.Add(TextBlock);
218 Control Result =
null;
219 bool MakeVisible =
false;
245 await this.Layout(Container,
MediaField, Form);
247 if (MakeVisible && this.makeVisible is
null)
248 this.makeVisible = Result;
255 TextBlock TextBlock =
new TextBlock()
257 TextWrapping = TextWrapping.Wrap,
263 Run Run =
new Run(
"*");
264 TextBlock.Inlines.Add(Run);
265 Run.Foreground =
new SolidColorBrush(Colors.Red);
270 CheckBox =
new CheckBox()
274 Margin =
new Thickness(0, 3, 0, 3),
276 ToolTip = Field.Description
280 CheckBox.IsChecked =
null;
282 CheckBox.IsChecked = IsChecked;
285 CheckBox.Background =
new SolidColorBrush(Colors.PeachPuff);
287 CheckBox.Background =
new SolidColorBrush(Colors.LightGray);
289 CheckBox.Click += this.CheckBox_Click;
291 Container.Children.Add(CheckBox);
296 private async
void CheckBox_Click(
object Sender, RoutedEventArgs e)
300 if (!(Sender is CheckBox CheckBox))
303 string Var = NameToVar(CheckBox.Name);
308 if (CheckBox.IsChecked.HasValue)
310 CheckBox.Background =
null;
312 this.CheckOkButtonEnabled();
316 CheckBox.Background =
new SolidColorBrush(Colors.LightGray);
326 private void CheckOkButtonEnabled()
332 this.OkButton.IsEnabled =
false;
338 this.OkButton.IsEnabled =
false;
343 this.OkButton.IsEnabled =
true;
348 TextBlock TextBlock =
new TextBlock()
350 TextWrapping = TextWrapping.Wrap,
351 Margin =
new Thickness(0, 5, 0, 5),
352 Text = Field.ValueString
355 Container.Children.Add(TextBlock);
360 TextBox TextBox = this.LayoutTextBox(Container,
Field);
361 TextBox.TextChanged += this.TextBox_TextChanged;
362 TextBox.AcceptsReturn =
true;
363 TextBox.AcceptsTab =
true;
364 TextBox.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
371 TextBox TextBox = this.LayoutTextBox(Container,
Field);
372 TextBox.TextChanged += this.TextBox_TextChanged;
379 TextBlock TextBlock =
new TextBlock()
381 TextWrapping = TextWrapping.Wrap,
387 Run Run =
new Run(
"*");
388 TextBlock.Inlines.Add(Run);
389 Run.Foreground =
new SolidColorBrush(Colors.Red);
392 GroupBox GroupBox =
new GroupBox();
393 Container.Children.Add(GroupBox);
394 GroupBox.Name = VarToName(
Field.
Var);
395 GroupBox.Header = TextBlock;
397 GroupBox.Margin =
new Thickness(5, 5, 5, 5);
399 StackPanel StackPanel =
new StackPanel();
400 GroupBox.Content = StackPanel;
401 StackPanel.Margin =
new Thickness(5, 5, 5, 5);
406 foreach (KeyValuePair<string, string> Option
in Field.
Options)
408 CheckBox =
new CheckBox()
410 Content = Option.Key,
412 Margin =
new Thickness(0, 3, 0, 3),
414 IsChecked = Array.IndexOf<
string>(Values, Option.Value) >= 0
418 CheckBox.Background =
new SolidColorBrush(Colors.PeachPuff);
420 CheckBox.Background =
new SolidColorBrush(Colors.LightGray);
422 CheckBox.Click += this.MultiListCheckBox_Click;
424 StackPanel.Children.Add(CheckBox);
427 GroupBox.Tag = this.LayoutErrorLabel(StackPanel,
Field);
432 private async
void MultiListCheckBox_Click(
object Sender, RoutedEventArgs e)
436 if (!(Sender is CheckBox CheckBox))
439 if (!(CheckBox.Parent is StackPanel StackPanel))
442 if (!(StackPanel.Parent is GroupBox GroupBox))
445 string Var = NameToVar(GroupBox.Name);
450 List<string> Values =
new List<string>();
452 foreach (UIElement Element
in StackPanel.Children)
454 CheckBox = Element as CheckBox;
455 if (CheckBox is
null)
458 if (CheckBox.IsChecked.HasValue && CheckBox.IsChecked.Value)
459 Values.Add((
string)CheckBox.Tag);
464 TextBlock ErrorLabel = (TextBlock)GroupBox.Tag;
469 Background =
new SolidColorBrush(Colors.PeachPuff);
470 this.OkButton.IsEnabled =
false;
472 if (!(ErrorLabel is
null))
475 ErrorLabel.Visibility = Visibility.Visible;
481 this.CheckOkButtonEnabled();
483 if (!(ErrorLabel is
null))
484 ErrorLabel.Visibility = Visibility.Collapsed;
487 foreach (UIElement Element
in StackPanel.Children)
489 CheckBox = Element as CheckBox;
490 if (CheckBox is
null)
493 CheckBox.Background = Background;
504 this.LayoutControlLabel(Container,
Field);
506 ComboBox ComboBox =
new ComboBox()
511 Margin =
new Thickness(0, 0, 0, 5)
515 ComboBox.Background =
new SolidColorBrush(Colors.PeachPuff);
517 ComboBox.Background =
new SolidColorBrush(Colors.LightGray);
523 foreach (KeyValuePair<string, string> P
in Field.
Options)
525 Item =
new ComboBoxItem()
531 ComboBox.Items.Add(Item);
537 ComboBox.IsEditable =
true;
539 ComboBox.AddHandler(System.Windows.Controls.Primitives.TextBoxBase.TextChangedEvent,
540 new TextChangedEventHandler(this.ComboBox_TextChanged));
546 ComboBox.IsEditable =
false;
547 ComboBox.SelectionChanged += this.ComboBox_SelectionChanged;
550 ComboBox.SelectedIndex = Array.FindIndex(
Field.
Options, (P) => P.Value.Equals(s));
553 Container.Children.Add(ComboBox);
554 ComboBox.Tag = this.LayoutErrorLabel(Container,
Field);
559 private async
void ComboBox_TextChanged(
object Sender, TextChangedEventArgs e)
563 if (!(Sender is ComboBox ComboBox))
566 string Var = NameToVar(ComboBox.Name);
571 TextBlock ErrorLabel = (TextBlock)ComboBox.Tag;
572 string s = ComboBox.Text;
574 if (ComboBox.SelectedItem is ComboBoxItem ComboBoxItem && ((
string)ComboBoxItem.Content) == s)
575 s = (
string)ComboBoxItem.Tag;
581 ComboBox.Background =
new SolidColorBrush(Colors.PeachPuff);
582 this.OkButton.IsEnabled =
false;
584 if (!(ErrorLabel is
null))
587 ErrorLabel.Visibility = Visibility.Visible;
592 ComboBox.Background =
null;
594 if (!(ErrorLabel is
null))
595 ErrorLabel.Visibility = Visibility.Collapsed;
597 this.CheckOkButtonEnabled();
606 private async
void ComboBox_SelectionChanged(
object Sender, SelectionChangedEventArgs e)
610 if (!(Sender is ComboBox ComboBox))
613 string Var = NameToVar(ComboBox.Name);
618 TextBlock ErrorLabel = (TextBlock)ComboBox.Tag;
621 if (!(ComboBox.SelectedItem is ComboBoxItem Item))
622 Value =
string.
Empty;
624 Value = (string)Item.Tag;
630 ComboBox.Background =
new SolidColorBrush(Colors.PeachPuff);
631 this.OkButton.IsEnabled =
false;
633 if (!(ErrorLabel is
null))
636 ErrorLabel.Visibility = Visibility.Visible;
642 ComboBox.Background =
null;
644 if (!(ErrorLabel is
null))
645 ErrorLabel.Visibility = Visibility.Collapsed;
647 this.CheckOkButtonEnabled();
658 MediaElement MediaElement;
660 Grade Best = Runtime.Inventory.Grade.NotAtAll;
662 bool IsImage =
false;
663 bool IsVideo =
false;
664 bool IsAudio =
false;
666 bool TopMarginLaidOut = this.LayoutControlLabel(Container,
Field);
668 foreach (KeyValuePair<string, Uri> P
in Field.Media.URIs)
670 if (P.Key.StartsWith(
"image/"))
676 else if (P.Key.StartsWith(
"video/"))
678 switch (P.Key.ToLower())
680 case "video/x-ms-asf":
681 case "video/x-ms-wvx":
682 case "video/x-ms-wm":
683 case "video/x-ms-wmx":
694 case "video/3gpp-tt":
696 case "video/h263-1998":
697 case "video/h263-2000":
699 case "video/h264-rcdo":
700 case "video/h264-svc":
716 else if (P.Key.StartsWith(
"audio/"))
718 switch (P.Key.ToLower())
720 case "audio/x-ms-wma":
721 case "audio/x-ms-wax":
722 case "audio/x-ms-wmv":
733 case "audio/amr-wb+":
735 case "audio/pcma-wb":
737 case "audio/pcmu-wb":
757 BitmapImage BitmapImage =
new System.Windows.Media.Imaging.BitmapImage();
758 BitmapImage.BeginInit();
761 if (!(
Field.Media.Binary is
null))
763 else if (!(Uri is
null))
764 BitmapImage.UriSource = Uri;
765 else if (!
string.IsNullOrEmpty(
Field.Media.URL))
766 BitmapImage.UriSource =
new Uri(
Field.Media.URL);
770 BitmapImage.EndInit();
773 Image Image =
new Image()
775 Source = BitmapImage,
777 Margin =
new Thickness(0, TopMarginLaidOut ? 0 : 5, 0, 5)
780 if (
Field.Media.Width.HasValue)
781 Image.Width =
Field.Media.Width.Value;
783 if (
Field.Media.Height.HasValue)
784 Image.Height =
Field.Media.Height.Value;
786 Container.Children.Add(Image);
788 else if (IsVideo || IsAudio)
790 MediaElement =
new MediaElement()
793 LoadedBehavior = MediaState.Manual,
794 ToolTip = Field.Description
797 Container.Children.Add(MediaElement);
801 MediaElement.Margin =
new Thickness(0, TopMarginLaidOut ? 0 : 5, 0, 5);
803 if (
Field.Media.Width.HasValue)
804 MediaElement.Width =
Field.Media.Width.Value;
806 if (
Field.Media.Height.HasValue)
807 MediaElement.Height =
Field.Media.Height.Value;
810 DockPanel ControlPanel =
new DockPanel()
815 Container.Children.Add(ControlPanel);
817 Button Button =
new Button()
821 Margin =
new Thickness(0, 0, 5, 0),
826 ControlPanel.Children.Add(Button);
827 Button.Click += this.Rewind_Click;
829 Button =
new Button()
833 Margin =
new Thickness(5, 0, 5, 0),
838 ControlPanel.Children.Add(Button);
839 Button.Click += this.Play_Click;
841 Button =
new Button()
845 Margin =
new Thickness(5, 0, 5, 0),
850 ControlPanel.Children.Add(Button);
851 Button.Click += this.Pause_Click;
853 Button =
new Button()
857 Margin =
new Thickness(5, 0, 5, 0),
862 ControlPanel.Children.Add(Button);
863 Button.Click += this.Stop_Click;
865 Button =
new Button()
869 Margin =
new Thickness(5, 0, 0, 0),
874 ControlPanel.Children.Add(Button);
875 Button.Click += this.Forward_Click;
881 private void Rewind_Click(
object Sender, RoutedEventArgs e)
883 Button Button = (Button)Sender;
884 MediaElement MediaElement = (MediaElement)Button.Tag;
886 if (!(MediaElement is
null))
888 if (MediaElement.SpeedRatio >= 0)
889 MediaElement.SpeedRatio = -1;
890 else if (MediaElement.SpeedRatio > -32)
891 MediaElement.SpeedRatio *= 2;
895 private void Play_Click(
object Sender, RoutedEventArgs e)
897 Button Button = (Button)Sender;
898 MediaElement MediaElement = (MediaElement)Button.Tag;
900 if (!(MediaElement is
null))
902 if (MediaElement.Position >= MediaElement.NaturalDuration.TimeSpan)
905 MediaElement.Position = TimeSpan.Zero;
912 private void Pause_Click(
object Sender, RoutedEventArgs e)
914 Button Button = (Button)Sender;
915 MediaElement MediaElement = (MediaElement)Button.Tag;
916 MediaElement?.Pause();
919 private void Stop_Click(
object Sender, RoutedEventArgs e)
921 Button Button = (Button)Sender;
922 MediaElement MediaElement = (MediaElement)Button.Tag;
923 MediaElement?.Stop();
926 private void Forward_Click(
object Sender, RoutedEventArgs e)
928 Button Button = (Button)Sender;
929 MediaElement MediaElement = (MediaElement)Button.Tag;
931 if (!(MediaElement is
null))
933 if (MediaElement.SpeedRatio <= 0)
934 MediaElement.SpeedRatio = 1;
935 else if (MediaElement.SpeedRatio < 32)
936 MediaElement.SpeedRatio *= 2;
942 this.LayoutControlLabel(Container,
Field);
950 Margin =
new Thickness(0, 0, 0, 5)
954 Editor.Background =
new SolidColorBrush(Colors.PeachPuff);
956 Editor.Background =
new SolidColorBrush(Colors.LightGray);
958 Container.Children.Add(Editor);
959 Editor.Tag = this.LayoutErrorLabel(Container,
Field);
961 Editor.TextChanged += this.Editor_TextChanged;
962 Editor.BorderBrush =
new SolidColorBrush(SystemColors.ActiveBorderColor);
963 Editor.BorderThickness =
new Thickness(1);
964 Editor.Padding =
new Thickness(5, 2, 5, 2);
965 Editor.HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden;
966 Editor.VerticalScrollBarVisibility = ScrollBarVisibility.Hidden;
968 Editor.Height =
double.NaN;
969 Editor.Width =
double.NaN;
970 Editor.Options.ShowSpaces =
false;
971 Editor.Options.ShowTabs =
false;
974 string SyntaxHighlightingResource =
null;
979 Editor.WordWrap =
true;
982 case "text/markdown":
983 Editor.WordWrap =
true;
984 SyntaxHighlightingResource =
"Markdown.xshd";
988 Editor.FontFamily =
new FontFamily(
"Courier New");
989 Editor.WordWrap =
false;
990 Editor.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
991 SyntaxHighlightingResource =
"CSS.xshd";
996 case "text/tab-separated-values":
997 case "application/x-turtle":
999 case "application/sparql-query":
1000 Editor.FontFamily =
new FontFamily(
"Courier New");
1001 Editor.WordWrap =
false;
1002 Editor.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
1005 case "application/json":
1007 Editor.FontFamily =
new FontFamily(
"Courier New");
1008 Editor.WordWrap =
false;
1009 Editor.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
1010 SyntaxHighlightingResource =
"JSON.xshd";
1014 case "application/xml":
1016 Editor.FontFamily =
new FontFamily(
"Courier New");
1017 Editor.WordWrap =
false;
1018 Editor.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
1019 SyntaxHighlightingResource =
"XML.xshd";
1022 case "application/javascript":
1023 Editor.FontFamily =
new FontFamily(
"Courier New");
1024 Editor.WordWrap =
false;
1025 Editor.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
1026 SyntaxHighlightingResource =
"JavaScript.xshd";
1030 Editor.FontFamily =
new FontFamily(
"Courier New");
1031 Editor.WordWrap =
true;
1032 SyntaxHighlightingResource =
"HTML.xshd";
1035 case "text/richtext":
1036 Editor.FontFamily =
new FontFamily(
"Courier New");
1037 Editor.WordWrap =
false;
1038 Editor.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
1041 case "application/x-webscript":
1042 Editor.FontFamily =
new FontFamily(
"Courier New");
1043 Editor.WordWrap =
false;
1044 Editor.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
1048 Editor.FontFamily =
new FontFamily(
"Courier New");
1049 Editor.WordWrap =
false;
1050 Editor.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
1051 SyntaxHighlightingResource =
"CSS.xshd";
1055 Editor.FontFamily =
new FontFamily(
"Courier New");
1056 Editor.WordWrap =
false;
1057 Editor.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
1060 SyntaxHighlightingResource =
"JSON.xshd";
1062 SyntaxHighlightingResource =
"XML.xshd";
1067 if (!
string.IsNullOrEmpty(SyntaxHighlightingResource))
1077 Type AppType = typeof(
App);
1079 using (Stream XshdStream = AppType.Assembly.GetManifestResourceStream(AppType.Namespace +
".Dialogs.AvalonExtensions." +
1080 SyntaxHighlightingResource))
1082 using (XmlReader XshdReader =
new XmlTextReader(XshdStream))
1084 Editor.SyntaxHighlighting = HighlightingLoader.Load(XshdReader, HighlightingManager.Instance);
1094 this.LayoutControlLabel(Container,
Field);
1096 PasswordBox PasswordBox =
new PasswordBox()
1102 Margin =
new Thickness(0, 0, 0, 5)
1106 PasswordBox.Background =
new SolidColorBrush(Colors.PeachPuff);
1108 PasswordBox.Background =
new SolidColorBrush(Colors.LightGray);
1110 PasswordBox.PasswordChanged += this.PasswordBox_PasswordChanged;
1112 Container.Children.Add(PasswordBox);
1113 PasswordBox.Tag = this.LayoutErrorLabel(Container,
Field);
1118 private async
void PasswordBox_PasswordChanged(
object Sender, RoutedEventArgs e)
1122 if (!(Sender is PasswordBox PasswordBox))
1125 string Var = NameToVar(PasswordBox.Name);
1132 TextBlock ErrorLabel = (TextBlock)PasswordBox.Tag;
1136 PasswordBox.Background =
new SolidColorBrush(Colors.PeachPuff);
1137 this.OkButton.IsEnabled =
false;
1139 if (!(ErrorLabel is
null))
1142 ErrorLabel.Visibility = Visibility.Visible;
1147 PasswordBox.Background =
null;
1149 if (!(ErrorLabel is
null))
1150 ErrorLabel.Visibility = Visibility.Collapsed;
1152 this.CheckOkButtonEnabled();
1155 catch (Exception ex)
1163 TextBox TextBox = this.LayoutTextBox(Container,
Field);
1164 TextBox.TextChanged += this.TextBox_TextChanged;
1169 private TextBox LayoutTextBox(Panel Container,
Field Field)
1171 this.LayoutControlLabel(Container,
Field);
1173 TextBox TextBox =
new TextBox()
1179 Margin =
new Thickness(0, 0, 0, 5)
1183 TextBox.Background =
new SolidColorBrush(Colors.PeachPuff);
1185 TextBox.Background =
new SolidColorBrush(Colors.LightGray);
1187 Container.Children.Add(TextBox);
1188 TextBox.Tag = this.LayoutErrorLabel(Container,
Field);
1193 private TextBlock LayoutErrorLabel(Panel Container,
Field Field)
1195 TextBlock ErrorLabel =
new TextBlock()
1197 TextWrapping = TextWrapping.Wrap,
1198 Margin =
new Thickness(0, 0, 0, 5),
1200 Foreground =
new SolidColorBrush(Colors.Red),
1201 FontWeight = FontWeights.Bold,
1202 Visibility = Field.HasError ? Visibility.Visible : Visibility.Collapsed
1205 Container.Children.Add(ErrorLabel);
1210 private bool LayoutControlLabel(Panel Container,
Field Field)
1216 TextBlock TextBlock =
new TextBlock()
1218 TextWrapping = TextWrapping.Wrap,
1220 Margin =
new Thickness(0, 5, 0, 0)
1223 Container.Children.Add(TextBlock);
1227 Run Run =
new Run(
"*");
1228 TextBlock.Inlines.Add(Run);
1229 Run.Foreground =
new SolidColorBrush(Colors.Red);
1236 private async
void TextBox_TextChanged(
object Sender, TextChangedEventArgs e)
1240 if (!(Sender is TextBox TextBox))
1243 string Var = NameToVar(TextBox.Name);
1248 TextBlock ErrorLabel = (TextBlock)TextBox.Tag;
1250 await
Field.
SetValue(TextBox.Text.Replace(
"\r\n",
"\n").Replace(
"\r",
"\n").Split(
'\n'));
1254 TextBox.Background =
new SolidColorBrush(Colors.PeachPuff);
1255 this.OkButton.IsEnabled =
false;
1256 if (!(ErrorLabel is
null))
1259 ErrorLabel.Visibility = Visibility.Visible;
1264 TextBox.Background =
null;
1266 if (!(ErrorLabel is
null))
1267 ErrorLabel.Visibility = Visibility.Collapsed;
1269 this.CheckOkButtonEnabled();
1272 catch (Exception ex)
1278 private async
void Editor_TextChanged(
object Sender, EventArgs e)
1285 string Var = NameToVar(Editor.Name);
1290 TextBlock ErrorLabel = (TextBlock)Editor.Tag;
1292 await
Field.
SetValue(Editor.Text.Replace(
"\r\n",
"\n").Replace(
"\r",
"\n").Split(
'\n'));
1296 Editor.Background =
new SolidColorBrush(Colors.PeachPuff);
1297 this.OkButton.IsEnabled =
false;
1298 if (!(ErrorLabel is
null))
1301 ErrorLabel.Visibility = Visibility.Visible;
1306 Editor.Background =
null;
1308 if (!(ErrorLabel is
null))
1309 ErrorLabel.Visibility = Visibility.Collapsed;
1311 this.CheckOkButtonEnabled();
1314 catch (Exception ex)
1325 Dictionary<string, int> VarIndex =
new Dictionary<string, int>();
1326 ColumnDefinition ColumnDefinition;
1327 RowDefinition RowDefinition;
1328 TextBlock TextBlock;
1331 Brush BorderBrush =
new SolidColorBrush(Colors.Gray);
1332 Brush Bg1 =
new SolidColorBrush(Color.FromArgb(0x20, 0x40, 0x40, 0x40));
1333 Brush Bg2 =
new SolidColorBrush(Color.FromArgb(0x10, 0x80, 0x80, 0x80));
1335 Grid Grid =
new Grid();
1336 Container.Children.Add(Grid);
1341 ColumnDefinition =
new ColumnDefinition()
1343 Width = GridLength.Auto
1346 Grid.ColumnDefinitions.Add(ColumnDefinition);
1351 RowDefinition =
new RowDefinition()
1353 Height = GridLength.Auto
1356 Grid.RowDefinitions.Add(RowDefinition);
1360 RowDefinition =
new RowDefinition()
1362 Height = GridLength.Auto
1365 Grid.RowDefinitions.Add(RowDefinition);
1370 if (!VarIndex.TryGetValue(
Field.
Var, out i))
1373 Border =
new Border();
1374 Grid.Children.Add(Border);
1376 Grid.SetColumn(Border, i);
1377 Grid.SetRow(Border, 0);
1379 Border.BorderBrush = BorderBrush;
1380 Border.BorderThickness =
new Thickness(1);
1381 Border.Padding =
new Thickness(5, 1, 5, 1);
1382 Border.Background = Bg1;
1384 TextBlock =
new TextBlock()
1386 FontWeight = FontWeights.Bold,
1390 Border.Child = TextBlock;
1400 if (!VarIndex.TryGetValue(
Field.
Var, out i))
1403 Border =
new Border();
1404 Grid.Children.Add(Border);
1406 Grid.SetColumn(Border, i);
1407 Grid.SetRow(Border, j);
1409 Border.BorderBrush = BorderBrush;
1410 Border.BorderThickness =
new Thickness(1);
1411 Border.Padding =
new Thickness(5, 1, 5, 1);
1414 Border.Background = Bg2;
1416 Border.Background = Bg1;
1418 TextBlock =
new TextBlock()
1420 Text = Field.ValueString
1423 Border.Child = TextBlock;
1430 private async
void OkButton_Click(
object Sender, RoutedEventArgs e)
1434 await this.form.Submit();
1436 this.DialogResult =
true;
1438 catch (Exception ex)
1444 private async
void CancelButton_Click(
object Sender, RoutedEventArgs e)
1448 await this.form.Cancel();
1450 this.DialogResult =
false;
1452 catch (Exception ex)
1458 private void Window_Activated(
object Sender, EventArgs e)
1460 if (!(this.makeVisible is
null))
1462 LinkedList<FrameworkElement> List =
new LinkedList<FrameworkElement>();
1464 while (!(this.makeVisible is
null))
1466 List.AddFirst(this.makeVisible);
1467 this.makeVisible = this.makeVisible.Parent as FrameworkElement;
1470 foreach (FrameworkElement E
in List)
1480 private static string VarToName(
string Var)
1482 return "Form_" + Var.Replace(
"#",
"__GATO__");
1485 private static string NameToVar(
string Name)
1487 return Name.Substring(5).Replace(
"__GATO__",
"#");
Interaction logic for App.xaml
Avalon editor that does not capture mouse wheel (scrolling) events.
Interaction logic for ParameterDialog.xaml
void InitializeComponent()
InitializeComponent
bool Empty
If the dialog is empty.
static async Task< ParameterDialog > CreateAsync(DataForm Form)
Interaction logic for ParameterDialog.xaml
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.
static Task< string > GetTemporaryFile(byte[] BinaryImage)
Stores an image in binary form as a temporary file. Files will be deleted when application closes.
Plain text encoder/decoder.
const string DefaultContentType
text/plain
Static class managing the application event log. Applications and services log events on this static ...
static void Exception(Exception Exception, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, params KeyValuePair< string, object >[] Tags)
Logs an exception. Event type will be determined by the severity of the exception.
Class managing a page in a data form layout.
Class managing a text element.
HorizontalAlignment
Horizontal alignment
ContentType
DTLS Record content type.