DynamicFormDesignWindow.xaml.cs 2.5 KB

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