AITInterlockSensor.xaml.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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.Sorter.UI.Controls
  16. {
  17. /// <summary>
  18. /// AITInterlockSensor.xaml 的交互逻辑
  19. /// </summary>
  20. public partial class AITInterlockSensor : UserControl
  21. {
  22. public static readonly DependencyProperty DeviceDataProperty = DependencyProperty.Register(
  23. "DeviceData", typeof(AITSensorData), typeof(AITInterlockSensor),
  24. new FrameworkPropertyMetadata(new AITSensorData(), FrameworkPropertyMetadataOptions.AffectsRender));
  25. public AITSensorData DeviceData
  26. {
  27. get
  28. {
  29. return (AITSensorData)this.GetValue(DeviceDataProperty);
  30. }
  31. set
  32. {
  33. this.SetValue(DeviceDataProperty, value);
  34. }
  35. }
  36. public bool LightOnValue
  37. {
  38. get { return (bool)GetValue(LightOnValueProperty); }
  39. set { SetValue(LightOnValueProperty, value); }
  40. }
  41. public static readonly DependencyProperty LightOnValueProperty =
  42. DependencyProperty.Register("LightOnValue", typeof(bool), typeof(AITInterlockSensor), new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.AffectsRender));
  43. public AITInterlockSensor()
  44. {
  45. InitializeComponent();
  46. }
  47. protected override void OnRender(DrawingContext drawingContext)
  48. {
  49. base.OnRender(drawingContext);
  50. if (DeviceData == null)
  51. {
  52. sensor.Fill = new SolidColorBrush(Colors.Gray);
  53. return;
  54. }
  55. if (DeviceData.Value == LightOnValue)
  56. sensor.Fill = new SolidColorBrush(Colors.Red);
  57. else
  58. {
  59. sensor.Fill = new SolidColorBrush(Colors.Gray);
  60. }
  61. //if (DeviceData.IsError)
  62. // sensor.Fill = new SolidColorBrush(Colors.Red);
  63. //else
  64. //{
  65. // sensor.Fill = new SolidColorBrush(Colors.Lime);
  66. //}
  67. }
  68. private void Grid_MouseEnter(object sender, MouseEventArgs e)
  69. {
  70. if (DeviceData != null)
  71. {
  72. string tooltipValue =
  73. string.Format(Application.Current.Resources["GlobalLableSensorToolTip"].ToString(),
  74. "Sensor",
  75. DeviceData.DisplayName,
  76. DeviceData.DeviceSchematicId,
  77. DeviceData.Value);
  78. ToolTip = tooltipValue;
  79. }
  80. }
  81. }
  82. }