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

102 lines
3.1 KiB

  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 BeDesignerSCADA.CustomerControls
  19. {
  20. public class StatusLight : Control, IExecutable
  21. {
  22. public event EventHandler PropertyChange; //声明一个事件
  23. public StatusLight()
  24. {
  25. Width = 80;
  26. Height = 80;
  27. }
  28. public string ControlType => "控件";
  29. static StatusLight()
  30. {
  31. DefaultStyleKeyProperty.OverrideMetadata(typeof(StatusLight), new FrameworkPropertyMetadata(typeof(StatusLight)));
  32. }
  33. private bool isExecuteState;
  34. public bool IsExecuteState
  35. {
  36. get { return isExecuteState; }
  37. set
  38. {
  39. isExecuteState = value;
  40. if (IsExecuteState)
  41. {
  42. Register();
  43. }
  44. }
  45. }
  46. /// <summary>
  47. /// 状态值
  48. /// </summary>
  49. [Category("值设定")]
  50. public int StatusValue
  51. {
  52. get { return (int)GetValue(StatusValueProperty); }
  53. set { SetValue(StatusValueProperty, value); }
  54. }
  55. public static readonly DependencyProperty StatusValueProperty =
  56. DependencyProperty.Register("StatusValue", typeof(int), typeof(StatusLight), new UIPropertyMetadata(0, OnStatusChanged));
  57. private static void OnStatusChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) => (d as StatusLight).Refresh();
  58. private void Refresh()
  59. {
  60. if (image != null)
  61. {
  62. switch (StatusValue)
  63. {
  64. case 0:
  65. image.Source = new BitmapImage(new Uri("pack://application:,,,/Images/State0.png", UriKind.Absolute));
  66. break;
  67. case -1:
  68. image.Source = new BitmapImage(new Uri("pack://application:,,,/Images/State11.png", UriKind.Absolute));
  69. break;
  70. case 1:
  71. image.Source = new BitmapImage(new Uri("pack://application:,,,/Images/State1.png", UriKind.Absolute));
  72. break;
  73. case 2:
  74. image.Source = new BitmapImage(new Uri("pack://application:,,,/Images/State2.png", UriKind.Absolute));
  75. break;
  76. default:
  77. break;
  78. }
  79. }
  80. }
  81. Image image;
  82. public override void OnApplyTemplate()
  83. {
  84. base.OnApplyTemplate();
  85. image = GetTemplateChild("ima") as Image;
  86. Refresh();
  87. }
  88. public void Register()
  89. {
  90. }
  91. }
  92. }