终端一体化运控平台
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.

StatusLight.cs 3.2 KiB

2 jaren geleden
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. using BPASmartClient.Compiler;
  2. using BPASmartClient.SCADAControl;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows;
  10. using System.Windows.Controls;
  11. using System.Windows.Data;
  12. using System.Windows.Documents;
  13. using System.Windows.Input;
  14. using System.Windows.Media;
  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. /// 状态标志
  22. /// </summary>
  23. public class StatusLight : Control, IExecutable
  24. {
  25. public event EventHandler PropertyChange; //声明一个事件
  26. public StatusLight()
  27. {
  28. Width = 80;
  29. Height = 80;
  30. }
  31. public string ControlType => "控件";
  32. static StatusLight()
  33. {
  34. DefaultStyleKeyProperty.OverrideMetadata(typeof(StatusLight), new FrameworkPropertyMetadata(typeof(StatusLight)));
  35. }
  36. private bool isExecuteState;
  37. public bool IsExecuteState
  38. {
  39. get { return isExecuteState; }
  40. set
  41. {
  42. isExecuteState = value;
  43. if (IsExecuteState)
  44. {
  45. Register();
  46. }
  47. }
  48. }
  49. /// <summary>
  50. /// 状态值
  51. /// </summary>
  52. [Category("值设定")]
  53. public int StatusValue
  54. {
  55. get { return (int)GetValue(StatusValueProperty); }
  56. set { SetValue(StatusValueProperty, value); }
  57. }
  58. public static readonly DependencyProperty StatusValueProperty =
  59. DependencyProperty.Register("StatusValue", typeof(int), typeof(StatusLight), new UIPropertyMetadata(0, OnStatusChanged));
  60. private static void OnStatusChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) => (d as StatusLight).Refresh();
  61. private void Refresh()
  62. {
  63. if (image != null)
  64. {
  65. switch (StatusValue)
  66. {
  67. case 0:
  68. image.Source = new BitmapImage(new Uri(@"/BPASmartClient.SCADAControl;component/Images/State0.png", UriKind.Relative));
  69. break;
  70. case -1:
  71. image.Source = new BitmapImage(new Uri(@"/BPASmartClient.SCADAControl;component/Images/State11.png", UriKind.Relative));
  72. break;
  73. case 1:
  74. image.Source = new BitmapImage(new Uri(@"/BPASmartClient.SCADAControl;component/Images/State1.png", UriKind.Relative));
  75. break;
  76. case 2:
  77. image.Source = new BitmapImage(new Uri(@"/BPASmartClient.SCADAControl;component/Images/State2.png", UriKind.Relative));
  78. break;
  79. default:
  80. break;
  81. }
  82. }
  83. }
  84. Image image;
  85. public override void OnApplyTemplate()
  86. {
  87. base.OnApplyTemplate();
  88. image = GetTemplateChild("ima") as Image;
  89. Refresh();
  90. }
  91. public void Register()
  92. {
  93. }
  94. }
  95. }