终端一体化运控平台
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 

143 lignes
5.0 KiB

  1. using BPASmartClient.Compiler;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Collections.ObjectModel;
  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.Navigation;
  16. using System.Windows.Shapes;
  17. namespace BPASmartClient.SCADAControl.CustomerControls
  18. {
  19. /// <summary>
  20. /// TheRectangle.xaml 的交互逻辑
  21. /// </summary>
  22. public partial class TheRectangle : UserControl, IExecutable
  23. {
  24. Border LeftTog = null;
  25. public TheRectangle()
  26. {
  27. InitializeComponent();
  28. this.Loaded += TheRectangle_Loaded; ;
  29. this.SizeChanged += TheRectangle_SizeChanged; ;
  30. }
  31. private void TheRectangle_SizeChanged(object sender, SizeChangedEventArgs e)
  32. {
  33. if (LeftTog == null)
  34. {
  35. foreach (Border tb in FindVisualChildren<Border>(this))
  36. {
  37. if (tb.Tag != null)
  38. {
  39. if (tb.Tag.ToString() == "border") LeftTog = tb;
  40. }
  41. }
  42. }
  43. }
  44. public static IEnumerable<T> FindVisualChildren<T>(DependencyObject depObj) where T : DependencyObject
  45. {
  46. if (depObj != null)
  47. {
  48. for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
  49. {
  50. DependencyObject child = VisualTreeHelper.GetChild(depObj, i);
  51. if (child != null && child is T)
  52. {
  53. yield return (T)child;
  54. }
  55. foreach (T childOfChild in FindVisualChildren<T>(child))
  56. {
  57. yield return childOfChild;
  58. }
  59. }
  60. }
  61. }
  62. private void TheRectangle_Loaded(object sender, RoutedEventArgs e)
  63. {
  64. if (this.ActualWidth <= 20)
  65. {
  66. Width = 80;
  67. Height = 80;
  68. }
  69. BKStrokeDashArray.CollectionChanged += BKStrokeDashArray_CollectionChanged;
  70. }
  71. private void BKStrokeDashArray_CollectionChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
  72. {
  73. Refresh();
  74. }
  75. private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  76. {
  77. (d as TheRectangle)?.Refresh();
  78. }
  79. private void Refresh()
  80. {
  81. DoubleArray = new DoubleCollection(BKStrokeDashArray);
  82. }
  83. public Brush BJColor
  84. {
  85. get { return (Brush)GetValue(BJColorProperty); }
  86. set { SetValue(BJColorProperty, value); }
  87. }
  88. public static readonly DependencyProperty BJColorProperty =
  89. DependencyProperty.Register("BJColor", typeof(Brush), typeof(TheRectangle), new PropertyMetadata(new SolidColorBrush(Colors.Transparent)));
  90. public double BKThickness
  91. {
  92. get { return (double)GetValue(BKThicknessProperty); }
  93. set { SetValue(BKThicknessProperty, value); }
  94. }
  95. public static readonly DependencyProperty BKThicknessProperty =
  96. DependencyProperty.Register("BKThickness", typeof(double), typeof(TheRectangle), new PropertyMetadata(1.0));
  97. public ObservableCollection<double> BKStrokeDashArray
  98. {
  99. get { return (ObservableCollection<double>)GetValue(BKStrokeDashArrayProperty); }
  100. set { SetValue(BKStrokeDashArrayProperty, value); }
  101. }
  102. public static readonly DependencyProperty BKStrokeDashArrayProperty =
  103. DependencyProperty.Register("BKStrokeDashArray", typeof(ObservableCollection<double>), typeof(TheRectangle), new PropertyMetadata(new ObservableCollection<double>(), new PropertyChangedCallback(OnPropertyChanged)));
  104. public DoubleCollection DoubleArray
  105. {
  106. get { return (DoubleCollection)GetValue(DoubleArrayProperty); }
  107. set { SetValue(DoubleArrayProperty, value); }
  108. }
  109. public static readonly DependencyProperty DoubleArrayProperty =
  110. DependencyProperty.Register("DoubleArray", typeof(DoubleCollection), typeof(TheRectangle), new PropertyMetadata(new DoubleCollection()));
  111. public event EventHandler PropertyChange; //声明一个事件
  112. public string ControlType => "控件";
  113. private bool isExecuteState;
  114. public bool IsExecuteState
  115. {
  116. get { return isExecuteState; }
  117. set
  118. {
  119. isExecuteState = value;
  120. if (IsExecuteState)
  121. {
  122. Register();
  123. }
  124. }
  125. }
  126. // <summary>
  127. /// 运行事件
  128. /// </summary>
  129. public void Register()
  130. {
  131. }
  132. }
  133. }