终端一体化运控平台
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 

105 satır
3.2 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 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("pack://application:,,,/Images/State0.png", UriKind.Absolute));
  69. break;
  70. case -1:
  71. image.Source = new BitmapImage(new Uri("pack://application:,,,/Images/State11.png", UriKind.Absolute));
  72. break;
  73. case 1:
  74. image.Source = new BitmapImage(new Uri("pack://application:,,,/Images/State1.png", UriKind.Absolute));
  75. break;
  76. case 2:
  77. image.Source = new BitmapImage(new Uri("pack://application:,,,/Images/State2.png", UriKind.Absolute));
  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. }