AITWaterFlowSensor.xaml.cs 2.7 KB

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