终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

168 lines
6.3 KiB

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