终端一体化运控平台
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 

124 righe
4.1 KiB

  1. using BeDesignerSCADA.Common;
  2. using BeDesignerSCADA.Controls;
  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.Markup;
  14. using System.Windows.Media;
  15. using System.Windows.Media.Imaging;
  16. using System.Windows.Shapes;
  17. using System.Xml;
  18. namespace BeDesignerSCADA.View
  19. {
  20. /// <summary>
  21. /// ChildEditWindow.xaml 的交互逻辑
  22. /// </summary>
  23. public partial class ChildEditWindow : Window
  24. {
  25. public ChildEditWindow()
  26. {
  27. InitializeComponent();
  28. EditorHelper.Register<BindingExpression, BindingConvertor>();
  29. Owner = Application.Current.MainWindow;
  30. Closing += (s, e) => { e.Cancel = true; Hide(); };
  31. }
  32. public static ChildEditWindow Instance { get; } = new ChildEditWindow();
  33. public static string ShowEdit(string xml)
  34. {
  35. try
  36. {
  37. // 获取所有控件的可用属性
  38. Instance.main.Child = new MainCanvasPanel("");
  39. if (!string.IsNullOrEmpty(xml))
  40. {
  41. FrameworkElement element = XamlReader.Parse(xml) as FrameworkElement;
  42. if (element != null && element is Canvas)
  43. {
  44. (Instance.main.Child as MainCanvasPanel).LoadFrameworkElement(((element as Canvas).Children));
  45. }
  46. }
  47. Instance.ShowDialog();
  48. if (Instance.IsOk)
  49. {
  50. Canvas grid = new Canvas();
  51. List<FrameworkElement> children = new List<FrameworkElement>();
  52. foreach (FrameworkElement item in (Instance.main.Child as MainCanvasPanel).cav.Children)
  53. {
  54. children.Add(item);
  55. }
  56. double gd = children==null || children.Count<=0?60: children.Max((FrameworkElement x) => Canvas.GetTop(x) + x.ActualHeight);
  57. double wd = children == null || children.Count <= 0 ? 100 : children.Max((FrameworkElement x) => Canvas.GetLeft(x) + x.ActualWidth);
  58. grid.Width = wd;
  59. grid.Height = gd+5;
  60. (Instance.main.Child as MainCanvasPanel).GetChildren()?.ForEach(child => {
  61. grid.Children.Add(child);
  62. });
  63. return FrameworkElementToXml(grid);
  64. }
  65. else
  66. {
  67. return xml;
  68. }
  69. }
  70. catch (Exception ex)
  71. {
  72. return xml;
  73. }
  74. }
  75. /// <summary>
  76. /// 流转Xml
  77. /// </summary>
  78. /// <param name="framework"></param>
  79. public static string FrameworkElementToXml(FrameworkElement framework)
  80. {
  81. StringBuilder outstr = new StringBuilder();
  82. try
  83. {
  84. //this code need for right XML fomating
  85. XmlWriterSettings settings = new XmlWriterSettings
  86. {
  87. Indent = true,
  88. OmitXmlDeclaration = true
  89. };
  90. var dsm = new XamlDesignerSerializationManager(XmlWriter.Create(outstr, settings))
  91. {
  92. //this string need for turning on expression saving mode
  93. XamlWriterMode = XamlWriterMode.Expression
  94. };
  95. XamlWriter.Save(framework, dsm);
  96. }
  97. catch (Exception ex) { }
  98. return outstr.ToString();
  99. }
  100. public bool IsOk { get; set; }
  101. private void CancelBtn_Click(object sender, RoutedEventArgs e)
  102. {
  103. IsOk = false;
  104. Close();
  105. }
  106. private void ConfirmBtn_Click(object sender, RoutedEventArgs e)
  107. {
  108. IsOk = true;
  109. Close();
  110. }
  111. }
  112. }