AITPressureSensor.xaml.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. /// AITPressureSensor.xaml 的交互逻辑
  19. /// </summary>
  20. public partial class AITPressureSensor : UserControl
  21. {
  22. public static readonly DependencyProperty DeviceDataProperty = DependencyProperty.Register(
  23. "DeviceData", typeof(AITPressureSensorData), typeof(AITPressureSensor),
  24. new FrameworkPropertyMetadata(new AITPressureSensorData(), FrameworkPropertyMetadataOptions.AffectsRender));
  25. public AITPressureSensorData DeviceData
  26. {
  27. get
  28. {
  29. return (AITPressureSensorData)this.GetValue(DeviceDataProperty);
  30. }
  31. set
  32. {
  33. this.SetValue(DeviceDataProperty, value);
  34. }
  35. }
  36. public AITPressureSensor()
  37. {
  38. InitializeComponent();
  39. }
  40. protected override void OnRender(DrawingContext drawingContext)
  41. {
  42. base.OnRender(drawingContext);
  43. if (DeviceData == null)
  44. {
  45. sensor.Fill = new SolidColorBrush(Colors.DarkGray);
  46. return;
  47. }
  48. if (DeviceData.IsError)
  49. sensor.Fill = new SolidColorBrush(Colors.OrangeRed);
  50. else if (DeviceData.IsWarning || DeviceData.IsOutOfRange)
  51. sensor.Fill = new SolidColorBrush(Colors.Yellow);
  52. else
  53. {
  54. sensor.Fill = new SolidColorBrush(Colors.Lime);
  55. }
  56. }
  57. private void Grid_MouseEnter(object sender, MouseEventArgs e)
  58. {
  59. if (DeviceData != null)
  60. {
  61. string tooltipValue =
  62. string.Format(Application.Current.Resources["GlobalLablePressureSensorToolTip"].ToString(),
  63. "PS",
  64. DeviceData.DisplayName,
  65. DeviceData.DeviceSchematicId,
  66. DeviceData.FeedBack.ToString("F1"),
  67. DeviceData.Unit,
  68. DeviceData.IsError ? "Alarm" : (DeviceData.IsWarning ? "Warning" : (DeviceData.IsOutOfRange ? "Abnormal" : "Normal"))
  69. );
  70. ToolTip = tooltipValue;
  71. }
  72. }
  73. }
  74. }