AITThermalCouple.xaml.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. using Aitex.Core.UI.Control;
  16. namespace Aitex.Core.UI.DeviceControl
  17. {
  18. /// <summary>
  19. /// AITThermalCouple.xaml 的交互逻辑
  20. /// </summary>
  21. public partial class AITThermalCouple : UserControl
  22. {
  23. public AITThermalCouple()
  24. {
  25. InitializeComponent();
  26. }
  27. public static readonly DependencyProperty DeviceDataProperty = DependencyProperty.Register(
  28. "DeviceData", typeof(AITThermalCoupleData), typeof(AITThermalCouple),
  29. new FrameworkPropertyMetadata(new AITThermalCoupleData(), FrameworkPropertyMetadataOptions.AffectsRender));
  30. public static readonly DependencyProperty BackColorProperty = DependencyProperty.Register(
  31. "BackColor", typeof(Brush), typeof(AITThermalCouple),
  32. new FrameworkPropertyMetadata(Brushes.DarkMagenta, FrameworkPropertyMetadataOptions.AffectsRender));
  33. public static readonly DependencyProperty IsControlTcProperty = DependencyProperty.Register(
  34. "IsControlTc", typeof(bool), typeof(AITThermalCouple),
  35. new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.AffectsRender));
  36. public bool IsControlTc
  37. {
  38. get
  39. {
  40. return (bool)this.GetValue(IsControlTcProperty);
  41. }
  42. set
  43. {
  44. this.SetValue(IsControlTcProperty, value);
  45. }
  46. }
  47. /// <summary>
  48. /// set, get current progress value AnalogDeviceData
  49. /// </summary>
  50. public AITThermalCoupleData DeviceData
  51. {
  52. get
  53. {
  54. return (AITThermalCoupleData)this.GetValue(DeviceDataProperty);
  55. }
  56. set
  57. {
  58. this.SetValue(DeviceDataProperty, value);
  59. }
  60. }
  61. public Brush BackColor
  62. {
  63. get
  64. {
  65. return (Brush)this.GetValue(BackColorProperty);
  66. }
  67. set
  68. {
  69. this.SetValue(BackColorProperty, value);
  70. }
  71. }
  72. protected override void OnRender(DrawingContext drawingContext)
  73. {
  74. base.OnRender(drawingContext);
  75. Brush background = Brushes.DarkMagenta;
  76. Brush foreground = Brushes.LightYellow;
  77. if (!IsControlTc)
  78. {
  79. background = Brushes.DarkGray;
  80. foreground = Brushes.Black;
  81. }
  82. if (DeviceData != null)
  83. {
  84. //rectBkground.Stroke = DeviceData.IsOffline ? Brushes.Pink : new SolidColorBrush(System.Windows.Media.Color.FromRgb(0X37, 0X37, 0X37));
  85. //rectBkground.StrokeThickness = DeviceData.IsOffline ? 2 : 1;
  86. //else
  87. // labelValue.Foreground = DeviceData.IsOffline ? Brushes.Red : Brushes.LightYellow;
  88. if (DeviceData.IsBroken || DeviceData.IsAlarm)
  89. {
  90. background = Brushes.Red;
  91. }else if (DeviceData.IsOutOfTolerance)
  92. {
  93. background = Brushes.Gold;
  94. }
  95. }
  96. rectBkground.Fill = background;
  97. labelValue.Foreground = foreground;
  98. }
  99. public Window AnalogOwner { get; set; }
  100. private void Grid_MouseEnter(object sender, MouseEventArgs e)
  101. {
  102. if (DeviceData != null)
  103. {
  104. string tooltipValue =
  105. string.Format(Application.Current.Resources["GlobalLableThermoMeterToolTip"].ToString(),
  106. DeviceData.Type,
  107. DeviceData.DisplayName,
  108. DeviceData.DeviceSchematicId,
  109. DeviceData.FeedBack.ToString("F1"),
  110. DeviceData.Unit,
  111. DeviceData.IsAlarm ? "Alarm" : (DeviceData.IsWarning ? "Warning" : (DeviceData.IsOutOfTolerance ? "Abnormal" : "Normal")),
  112. DeviceData.IsBroken ? "Broken" : "Normal");
  113. ToolTip = tooltipValue;
  114. }
  115. }
  116. }
  117. }