终端一体化运控平台
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 

168 строки
6.2 KiB

  1. using BPASmartClient.Compiler;
  2. using System;
  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.Animation;
  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. /// TheCylinder.xaml 的交互逻辑
  21. /// 气缸
  22. /// </summary>
  23. public partial class TheCylinder : UserControl, IExecutable
  24. {
  25. #region 临时变量
  26. Ellipse LeftTog = null;
  27. Ellipse RightTog = null;
  28. Storyboard storyboard = new Storyboard();
  29. #endregion
  30. public TheCylinder()
  31. {
  32. InitializeComponent();
  33. Width = 389;
  34. Height = 100;
  35. this.SizeChanged += TheCylinder_SizeChanged;
  36. }
  37. #region 事件
  38. /// <summary>
  39. /// 字节改变
  40. /// </summary>
  41. /// <param name="sender"></param>
  42. /// <param name="e"></param>
  43. /// <exception cref="NotImplementedException"></exception>
  44. private void TheCylinder_SizeChanged(object sender, SizeChangedEventArgs e)
  45. {
  46. if (LeftTog == null)
  47. {
  48. foreach (Ellipse tb in FindVisualChildren<Ellipse>(this))
  49. {
  50. if (tb.Tag != null)
  51. {
  52. if (tb.Tag.ToString() == "LeftTog") LeftTog = tb;
  53. else if (tb.Tag.ToString() == "RightTog") RightTog = tb;
  54. }
  55. }
  56. //storyboard.RepeatBehavior = RepeatBehavior.Forever;
  57. //DoubleAnimationUsingKeyFrames animation = new DoubleAnimationUsingKeyFrames();
  58. //Storyboard.SetTarget(animation, ellipseControl);
  59. //Storyboard.SetTargetProperty(animation, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)"));
  60. //animation.KeyFrames.Add(new EasingDoubleKeyFrame(0, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0))));
  61. //animation.KeyFrames.Add(new EasingDoubleKeyFrame(180, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(1))));
  62. //animation.KeyFrames.Add(new EasingDoubleKeyFrame(360, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(2))));
  63. //storyboard.Children.Add(animation);
  64. }
  65. }
  66. public static IEnumerable<T> FindVisualChildren<T>(DependencyObject depObj) where T : DependencyObject
  67. {
  68. if (depObj != null)
  69. {
  70. for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
  71. {
  72. DependencyObject child = VisualTreeHelper.GetChild(depObj, i);
  73. if (child != null && child is T)
  74. {
  75. yield return (T)child;
  76. }
  77. foreach (T childOfChild in FindVisualChildren<T>(child))
  78. {
  79. yield return childOfChild;
  80. }
  81. }
  82. }
  83. }
  84. #endregion
  85. #region 属性
  86. public string ControlType => "控件";
  87. private bool isExecuteState;
  88. public bool IsExecuteState
  89. {
  90. get { return isExecuteState; }
  91. set
  92. {
  93. isExecuteState = value;
  94. if (IsExecuteState)
  95. {
  96. IsEnabled = true;
  97. Focusable = true;
  98. Register();
  99. }
  100. }
  101. }
  102. public event EventHandler PropertyChange; //声明一个事件
  103. public bool LeftTogIsChecked
  104. {
  105. get { return (bool)GetValue(LeftTogIsCheckedProperty); }
  106. set { SetValue(LeftTogIsCheckedProperty, value); }
  107. }
  108. public static readonly DependencyProperty LeftTogIsCheckedProperty =
  109. DependencyProperty.Register("LeftTogIsChecked", typeof(bool), typeof(TheCylinder),
  110. new PropertyMetadata(false, new PropertyChangedCallback(OnPropertyChanged)));
  111. public bool RightTogIsChecked
  112. {
  113. get { return (bool)GetValue(RightTogIsCheckedProperty); }
  114. set { SetValue(RightTogIsCheckedProperty, value); }
  115. }
  116. public static readonly DependencyProperty RightTogIsCheckedProperty =
  117. DependencyProperty.Register("RightTogIsChecked", typeof(bool), typeof(TheCylinder),
  118. new PropertyMetadata(false, new PropertyChangedCallback(OnPropertyChanged)));
  119. private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  120. {
  121. (d as TheCylinder)?.Refresh();
  122. }
  123. private void Refresh()
  124. {
  125. if (LeftTog != null)
  126. {
  127. LeftTog.Fill= LeftTogIsChecked?new SolidColorBrush(Colors.Green): new SolidColorBrush(Colors.Red);
  128. RightTog.Fill = RightTogIsChecked ? new SolidColorBrush(Colors.Green) : new SolidColorBrush(Colors.Red);
  129. }
  130. }
  131. /// <summary>
  132. /// 数据模板
  133. /// </summary>
  134. private Dictionary<string, object> DataModel
  135. {
  136. get { return (Dictionary<string, object>)GetValue(DataModelProperty); }
  137. set { SetValue(DataModelProperty, value); }
  138. }
  139. private static readonly DependencyProperty DataModelProperty =
  140. DependencyProperty.Register("DataModel", typeof(Dictionary<string, object>), typeof(TheCylinder), new PropertyMetadata(new Dictionary<string, object>()));
  141. #endregion
  142. /// <summary>
  143. /// 运行事件
  144. /// </summary>
  145. public void Register()
  146. {
  147. Class_DataBus.GetInstance().BindingAction += BindingActionHeader;
  148. }
  149. public void BindingActionHeader(object sender, EventArgs e)
  150. {
  151. this.Dispatcher.Invoke((Action)(() =>
  152. {
  153. DataModel = Class_DataBus.GetInstance().Dic_RedisDataBinding;
  154. PropertyChange?.Invoke(this, EventArgs.Empty);
  155. }));
  156. }
  157. }
  158. }