DynamicFormDesignWindow.xaml.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using InABox.Core;
  2. using Org.BouncyCastle.Bcpg;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Data;
  11. using System.Windows.Documents;
  12. using System.Windows.Input;
  13. using System.Windows.Media;
  14. using System.Windows.Media.Imaging;
  15. using System.Windows.Shapes;
  16. namespace InABox.DynamicGrid;
  17. /// <summary>
  18. /// Interaction logic for DynamicFormDesignWindow.xaml
  19. /// </summary>
  20. public partial class DynamicFormDesignWindow : Window, IDynamicFormWindow
  21. {
  22. public DynamicFormDesignWindow() : base()
  23. {
  24. InitializeComponent();
  25. Preview.Mode = FormMode.Designing;
  26. }
  27. public DynamicFormDesignGrid Grid => Preview;
  28. private DFLayoutType _type;
  29. public DFLayoutType Type
  30. {
  31. get => _type;
  32. set
  33. {
  34. _type = value;
  35. Width = _type == DFLayoutType.Mobile ? 600 : 1000;
  36. Height = 800;
  37. }
  38. }
  39. public bool Designing
  40. {
  41. get => Grid.Mode == FormMode.Designing;
  42. set
  43. {
  44. Grid.Mode = value
  45. ? FormMode.Designing
  46. : FormMode.Preview;
  47. SwitchView.Content = value ? "Preview" : "Design";
  48. }
  49. }
  50. public event DynamicFormDesignGrid.CreateVariableHandler OnCreateVariable
  51. {
  52. add => Grid.OnCreateVariable += value;
  53. remove => Grid.OnCreateVariable -= value;
  54. }
  55. public event DynamicFormDesignGrid.EditVariableHandler OnEditVariable
  56. {
  57. add => Grid.OnEditVariable += value;
  58. remove => Grid.OnEditVariable -= value;
  59. }
  60. public string SaveLayout()
  61. {
  62. return Grid.Form.SaveLayout();
  63. }
  64. private void SwitchView_Click(object sender, RoutedEventArgs e)
  65. {
  66. Designing = !Designing;
  67. }
  68. private void OK_Click(object sender, RoutedEventArgs e)
  69. {
  70. DialogResult = true;
  71. }
  72. private void Cancel_Click(object sender, RoutedEventArgs e)
  73. {
  74. DialogResult = false;
  75. }
  76. private void DynamicFormWindow_KeyDown(object sender, KeyEventArgs e)
  77. {
  78. Grid.HandleKeyDown(e);
  79. }
  80. }