SignalTower.xaml.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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 System.Windows.Media.Effects;
  15. using Aitex.Core.UI.ControlDataContext;
  16. namespace Aitex.Core.UI.Control
  17. {
  18. /// <summary>
  19. /// Interaction logic for SignalTower.xaml
  20. /// </summary>
  21. public partial class SignalTower : UserControl
  22. {
  23. public SignalTower()
  24. {
  25. InitializeComponent();
  26. redLightEffect.BlurRadius = 20;
  27. redLightEffect.Opacity = 1;
  28. redLightEffect.Color = Colors.Red;
  29. yellowLightEffect.BlurRadius = 20;
  30. yellowLightEffect.Opacity = 1;
  31. yellowLightEffect.Color = Colors.Yellow;
  32. greenLightEffect.BlurRadius = 20;
  33. greenLightEffect.Opacity = 1;
  34. greenLightEffect.Color = Colors.Green;
  35. blueLightEffect.BlurRadius = 20;
  36. blueLightEffect.Opacity = 1;
  37. blueLightEffect.Color = Colors.Blue;
  38. }
  39. public static readonly DependencyProperty DeviceDataProperty = DependencyProperty.Register(
  40. "DeviceData", typeof(SignalTowerDataItem), typeof(SignalTower),
  41. new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));
  42. public static readonly DependencyProperty BuzzingWarningConfigCommandProperty = DependencyProperty.Register(
  43. "BuzzingWarningConfigCallback", typeof(Action), typeof(SignalTower),
  44. new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.None));
  45. public Action BuzzingWarningConfigCallback
  46. {
  47. get
  48. {
  49. return (Action)GetValue(BuzzingWarningConfigCommandProperty);
  50. }
  51. set
  52. {
  53. SetValue(BuzzingWarningConfigCommandProperty, value);
  54. }
  55. }
  56. public SignalTowerDataItem DeviceData
  57. {
  58. get
  59. {
  60. return (SignalTowerDataItem)GetValue(DeviceDataProperty);
  61. }
  62. set
  63. {
  64. SetValue(DeviceDataProperty, value);
  65. }
  66. }
  67. DropShadowEffect redLightEffect = new DropShadowEffect();
  68. DropShadowEffect yellowLightEffect = new DropShadowEffect();
  69. DropShadowEffect greenLightEffect = new DropShadowEffect();
  70. DropShadowEffect blueLightEffect = new DropShadowEffect();
  71. public double OutLights = 0.2;
  72. protected override void OnRender(DrawingContext drawingContext)
  73. {
  74. base.OnRender(drawingContext);
  75. if (DeviceData == null)
  76. return;
  77. if (DeviceData.IsRedLightOn)
  78. {
  79. if (rectangle1.Opacity != 1)
  80. {
  81. rectangle1.Opacity = 1;
  82. rectangle1.Effect = redLightEffect;
  83. }
  84. }
  85. else
  86. {
  87. if (rectangle1.Opacity != OutLights)
  88. {
  89. rectangle1.Opacity = OutLights;
  90. rectangle1.Effect = null;
  91. }
  92. }
  93. if (DeviceData.IsYellowLightOn)
  94. {
  95. if (rectangle2.Opacity != 1)
  96. {
  97. rectangle2.Opacity = 1;
  98. rectangle2.Effect = yellowLightEffect;
  99. }
  100. }
  101. else
  102. {
  103. if (rectangle2.Opacity != OutLights)
  104. {
  105. rectangle2.Opacity = OutLights;
  106. rectangle2.Effect = null;
  107. }
  108. }
  109. if (DeviceData.IsGreenLightOn)
  110. {
  111. if (rectangle3.Opacity != 1)
  112. {
  113. rectangle3.Opacity = 1;
  114. rectangle3.Effect = greenLightEffect;
  115. }
  116. }
  117. else
  118. {
  119. if (rectangle3.Opacity != OutLights)
  120. {
  121. rectangle3.Opacity = OutLights;
  122. rectangle3.Effect = null;
  123. }
  124. }
  125. }
  126. private void rectangle2_PreviewMouseDown(object sender, MouseButtonEventArgs e)
  127. {
  128. if (BuzzingWarningConfigCallback != null)
  129. {
  130. BuzzingWarningConfigCallback.Invoke();
  131. }
  132. }
  133. }
  134. }