AITSensor.xaml.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Data;
  8. using System.Windows.Documents;
  9. using System.Windows.Input;
  10. using System.Windows.Media;
  11. using System.Windows.Media.Imaging;
  12. using System.Windows.Navigation;
  13. using System.Windows.Shapes;
  14. using Aitex.Core.Common.DeviceData;
  15. namespace Aitex.Core.UI.DeviceControl
  16. {
  17. /// <summary>
  18. /// AITSensor.xaml 的交互逻辑
  19. /// </summary>
  20. public partial class AITSensor : UserControl
  21. {
  22. public static readonly DependencyProperty DeviceDataProperty = DependencyProperty.Register(
  23. "DeviceData", typeof(AITSensorData), typeof(AITSensor),
  24. new FrameworkPropertyMetadata(new AITSensorData(), FrameworkPropertyMetadataOptions.AffectsRender));
  25. public AITSensorData DeviceData
  26. {
  27. get
  28. {
  29. return (AITSensorData)this.GetValue(DeviceDataProperty);
  30. }
  31. set
  32. {
  33. this.SetValue(DeviceDataProperty, value);
  34. }
  35. }
  36. /// <summary>
  37. /// 如果是InterlockSensor,value==1 就变红
  38. /// </summary>
  39. public static readonly DependencyProperty IsInterlockSensorProperty = DependencyProperty.Register(
  40. "IsInterlockSensor", typeof(bool), typeof(AITSensor),
  41. new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.AffectsRender));
  42. public bool IsInterlockSensor
  43. {
  44. get
  45. {
  46. return (bool)this.GetValue(IsInterlockSensorProperty);
  47. }
  48. set
  49. {
  50. this.SetValue(IsInterlockSensorProperty, value);
  51. }
  52. }
  53. public AITSensor()
  54. {
  55. InitializeComponent();
  56. }
  57. protected override void OnRender(DrawingContext drawingContext)
  58. {
  59. base.OnRender(drawingContext);
  60. if (DeviceData == null)
  61. {
  62. sensor.Fill = new SolidColorBrush(Colors.Gray);
  63. return;
  64. }
  65. if (IsInterlockSensor)
  66. {
  67. if (DeviceData.IsError)
  68. sensor.Fill = new SolidColorBrush(Colors.Red);
  69. else
  70. {
  71. sensor.Fill = new SolidColorBrush(Colors.Lime);
  72. }
  73. return;
  74. }
  75. if (DeviceData.Value)
  76. {
  77. sensor.Fill = new SolidColorBrush(Colors.Lime);
  78. }
  79. else
  80. {
  81. sensor.Fill = new SolidColorBrush(Colors.Gray);
  82. }
  83. }
  84. private void Grid_MouseEnter(object sender, MouseEventArgs e)
  85. {
  86. if (DeviceData != null)
  87. {
  88. string tooltipValue =
  89. string.Format(Application.Current.Resources["GlobalLableSensorToolTip"].ToString(),
  90. "Sensor",
  91. DeviceData.DisplayName,
  92. DeviceData.DeviceSchematicId,
  93. DeviceData.Value );
  94. ToolTip = tooltipValue;
  95. }
  96. }
  97. }
  98. }