DynamicFormDesignWindow.xaml.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. OK.Visibility = value ? Visibility.Collapsed : Visibility.Visible;
  35. Cancel.Visibility = value ? Visibility.Collapsed : Visibility.Visible;
  36. if (_readOnly)
  37. {
  38. Preview.Mode = FormMode.Preview;
  39. }
  40. }
  41. }
  42. public DynamicFormDesignGrid Grid => Preview;
  43. private DFLayoutType _type;
  44. public DFLayoutType Type
  45. {
  46. get => _type;
  47. set
  48. {
  49. _type = value;
  50. Width = _type == DFLayoutType.Mobile ? 600 : 1000;
  51. Height = 800;
  52. }
  53. }
  54. public bool Designing
  55. {
  56. get => Grid.Mode == FormMode.Designing;
  57. set
  58. {
  59. var val = ReadOnly ? false : value;
  60. Grid.Mode = val
  61. ? FormMode.Designing
  62. : FormMode.Preview;
  63. SwitchView.Content = val ? "Preview" : "Design";
  64. }
  65. }
  66. public event DynamicFormDesignGrid.CreateVariableHandler OnCreateVariable
  67. {
  68. add => Grid.OnCreateVariable += value;
  69. remove => Grid.OnCreateVariable -= value;
  70. }
  71. public event DynamicFormDesignGrid.EditVariableHandler OnEditVariable
  72. {
  73. add => Grid.OnEditVariable += value;
  74. remove => Grid.OnEditVariable -= value;
  75. }
  76. public string SaveLayout()
  77. {
  78. return Grid.Form.SaveLayout();
  79. }
  80. private void SwitchView_Click(object sender, RoutedEventArgs e)
  81. {
  82. Designing = !Designing;
  83. }
  84. private void OK_Click(object sender, RoutedEventArgs e)
  85. {
  86. DialogResult = true;
  87. }
  88. private void Cancel_Click(object sender, RoutedEventArgs e)
  89. {
  90. DialogResult = false;
  91. }
  92. private void DynamicFormWindow_KeyDown(object sender, KeyEventArgs e)
  93. {
  94. Grid.HandleKeyDown(e);
  95. }
  96. }