AITWaterFlowSensor.xaml.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. /// AITWaterFlowSensor.xaml 的交互逻辑
  19. /// </summary>
  20. public partial class AITWaterFlowSensor : UserControl
  21. {
  22. public static readonly DependencyProperty DeviceDataProperty = DependencyProperty.Register(
  23. "DeviceData", typeof(AITWaterFlowSensorData), typeof(AITWaterFlowSensor),
  24. new FrameworkPropertyMetadata(new AITWaterFlowSensorData(), FrameworkPropertyMetadataOptions.AffectsRender));
  25. public AITWaterFlowSensorData DeviceData
  26. {
  27. get
  28. {
  29. return (AITWaterFlowSensorData)this.GetValue(DeviceDataProperty);
  30. }
  31. set
  32. {
  33. this.SetValue(DeviceDataProperty, value);
  34. }
  35. }
  36. public AITWaterFlowSensor()
  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.IsOutOfTolerance)
  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["GlobalLableWaterFlowSensorToolTip"].ToString(),
  63. "WaterFlow",
  64. DeviceData.DisplayName,
  65. DeviceData.DeviceSchematicId,
  66. DeviceData.FeedBack.ToString("F1"),
  67. DeviceData.Unit,
  68. DeviceData.IsError ? "Alarm" : (DeviceData.IsWarning ? "Warning" : (DeviceData.IsOutOfTolerance ? "Abnormal" : "Normal"))
  69. );
  70. ToolTip = tooltipValue;
  71. }
  72. }
  73. }
  74. }