DynamicFormDesignWindow.xaml.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. public DynamicFormDesignGrid Grid => Preview;
  27. private DFLayoutType _type;
  28. public DFLayoutType Type
  29. {
  30. get => _type;
  31. set
  32. {
  33. _type = value;
  34. Width = _type == DFLayoutType.Mobile ? 600 : 1000;
  35. Height = 800;
  36. }
  37. }
  38. public bool Designing
  39. {
  40. get => Grid.Mode == FormMode.Designing;
  41. set
  42. {
  43. Grid.Mode = value
  44. ? FormMode.Designing
  45. : FormMode.Preview;
  46. SwitchView.Content = value ? "Preview" : "Design";
  47. }
  48. }
  49. public event DynamicFormDesignGrid.CreateVariableHandler OnCreateVariable
  50. {
  51. add => Grid.OnCreateVariable += value;
  52. remove => Grid.OnCreateVariable -= value;
  53. }
  54. public event DynamicFormDesignGrid.EditVariableHandler OnEditVariable
  55. {
  56. add => Grid.OnEditVariable += value;
  57. remove => Grid.OnEditVariable -= value;
  58. }
  59. public string SaveLayout()
  60. {
  61. return Grid.Form.SaveLayout();
  62. }
  63. private void SwitchView_Click(object sender, RoutedEventArgs e)
  64. {
  65. Designing = !Designing;
  66. }
  67. private void OK_Click(object sender, RoutedEventArgs e)
  68. {
  69. DialogResult = true;
  70. }
  71. private void Cancel_Click(object sender, RoutedEventArgs e)
  72. {
  73. DialogResult = false;
  74. }
  75. private void DynamicFormWindow_KeyDown(object sender, KeyEventArgs e)
  76. {
  77. Grid.HandleKeyDown(e);
  78. }
  79. }