AITInterlockSensor.xaml.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. using System.Windows;
  2. using System.Windows.Controls;
  3. using System.Windows.Input;
  4. using System.Windows.Media;
  5. using Aitex.Core.Common.DeviceData;
  6. namespace MECF.Framework.UI.Core.CommonControl
  7. {
  8. /// <summary>
  9. /// AITInterlockSensor.xaml 的交互逻辑
  10. /// </summary>
  11. public partial class AITInterlockSensor : UserControl
  12. {
  13. public static readonly DependencyProperty DeviceDataProperty = DependencyProperty.Register(
  14. "DeviceData", typeof(AITSensorData), typeof(AITInterlockSensor),
  15. new FrameworkPropertyMetadata(new AITSensorData(), FrameworkPropertyMetadataOptions.AffectsRender));
  16. public AITSensorData DeviceData
  17. {
  18. get
  19. {
  20. return (AITSensorData)this.GetValue(DeviceDataProperty);
  21. }
  22. set
  23. {
  24. this.SetValue(DeviceDataProperty, value);
  25. }
  26. }
  27. public bool LightOnValue
  28. {
  29. get { return (bool)GetValue(LightOnValueProperty); }
  30. set { SetValue(LightOnValueProperty, value); }
  31. }
  32. public static readonly DependencyProperty LightOnValueProperty =
  33. DependencyProperty.Register("LightOnValue", typeof(bool), typeof(AITInterlockSensor), new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.AffectsRender));
  34. public AITInterlockSensor()
  35. {
  36. InitializeComponent();
  37. }
  38. protected override void OnRender(DrawingContext drawingContext)
  39. {
  40. base.OnRender(drawingContext);
  41. if (DeviceData == null)
  42. {
  43. sensor.Fill = new SolidColorBrush(Colors.Gray);
  44. return;
  45. }
  46. if (DeviceData.Value == LightOnValue)
  47. sensor.Fill = new SolidColorBrush(Colors.Red);
  48. else
  49. {
  50. sensor.Fill = new SolidColorBrush(Colors.Gray);
  51. }
  52. //if (DeviceData.IsError)
  53. // sensor.Fill = new SolidColorBrush(Colors.Red);
  54. //else
  55. //{
  56. // sensor.Fill = new SolidColorBrush(Colors.Lime);
  57. //}
  58. }
  59. private void Grid_MouseEnter(object sender, MouseEventArgs e)
  60. {
  61. if (DeviceData != null)
  62. {
  63. string tooltipValue =
  64. string.Format(Application.Current.Resources["GlobalLableSensorToolTip"].ToString(),
  65. "Sensor",
  66. DeviceData.DisplayName,
  67. DeviceData.DeviceSchematicId,
  68. DeviceData.Value);
  69. ToolTip = tooltipValue;
  70. }
  71. }
  72. }
  73. }