PressureSwitchBig.xaml.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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.Animation;
  15. namespace Aitex.Core.UI.Control
  16. {
  17. /// <summary>
  18. /// Interaction logic for PressureSwitch.xaml
  19. /// </summary>
  20. public partial class PressureSwitchBig : UserControl
  21. {
  22. public PressureSwitchBig()
  23. {
  24. InitializeComponent();
  25. }
  26. public static readonly DependencyProperty IsManualModeProperty = DependencyProperty.Register(
  27. "IsManualModePS", typeof(bool), typeof(PressureSwitchBig),
  28. new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.AffectsRender));
  29. public static readonly DependencyProperty OrientationProperty = DependencyProperty.Register(
  30. "OrientationPS", typeof(Orientation), typeof(PressureSwitchBig),
  31. new FrameworkPropertyMetadata(Orientation.Horizontal, FrameworkPropertyMetadataOptions.AffectsRender));
  32. public static readonly DependencyProperty CheckOkProperty = DependencyProperty.Register(
  33. "CheckOk", typeof(bool), typeof(PressureSwitchBig),
  34. new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.AffectsRender));
  35. public static readonly DependencyProperty ReverseValueProperty = DependencyProperty.Register(
  36. "ReverseValue", typeof(bool), typeof(PressureSwitchBig),
  37. new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  38. /// <summary>
  39. /// checkok
  40. /// </summary>
  41. public bool CheckOk
  42. {
  43. get
  44. {
  45. return (bool)GetValue(CheckOkProperty);
  46. }
  47. set
  48. {
  49. SetValue(CheckOkProperty, value);
  50. }
  51. }
  52. /// <summary>
  53. /// checkok
  54. /// </summary>
  55. public bool ReverseValue
  56. {
  57. get
  58. {
  59. return (bool)GetValue(ReverseValueProperty);
  60. }
  61. set
  62. {
  63. SetValue(ReverseValueProperty, value);
  64. }
  65. }
  66. /// <summary>
  67. /// filter oritation
  68. /// </summary>
  69. public Orientation Orientation
  70. {
  71. get
  72. {
  73. return (Orientation)this.GetValue(OrientationProperty);
  74. }
  75. set
  76. {
  77. this.SetValue(OrientationProperty, value);
  78. }
  79. }
  80. /// <summary>
  81. /// valve on/off status
  82. /// </summary>
  83. public bool IsManualMode
  84. {
  85. get
  86. {
  87. return (bool)GetValue(IsManualModeProperty);
  88. }
  89. set
  90. {
  91. SetValue(IsManualModeProperty, value);
  92. }
  93. }
  94. /// <summary>
  95. /// context menu property
  96. /// </summary>
  97. private ContextMenu MouseClickMenu
  98. {
  99. get;
  100. set;
  101. }
  102. public string PressureName { get; set; }
  103. /// <summary>
  104. /// over rendering behavior
  105. /// </summary>
  106. /// <param name="drawingContext"></param>
  107. protected override void OnRender(DrawingContext drawingContext)
  108. {
  109. base.OnRender(drawingContext);
  110. switch (Orientation)
  111. {
  112. case Orientation.Horizontal:
  113. rotateTransform.Angle = 0;
  114. break;
  115. case Orientation.Vertical:
  116. rotateTransform.Angle = 90;
  117. break;
  118. default:
  119. break;
  120. }
  121. if (ReverseValue)
  122. FillValue(!CheckOk);
  123. else
  124. FillValue(CheckOk);
  125. }
  126. private void FillValue(bool checkValue)
  127. {
  128. if (checkValue)
  129. {
  130. this.ToolTip = PressureName + "压力正常";
  131. psEllipse.Fill = Brushes.Green;
  132. }
  133. else
  134. {
  135. this.ToolTip = PressureName + "压力报警";
  136. psEllipse.Fill = Brushes.Red;
  137. }
  138. }
  139. /// <summary>
  140. /// open
  141. /// </summary>
  142. /// <param name="sender"></param>
  143. /// <param name="e"></param>
  144. private void TurnOnValve(object sender, RoutedEventArgs e)
  145. {
  146. CheckOk = true;
  147. }
  148. /// <summary>
  149. /// close
  150. /// </summary>
  151. /// <param name="sender"></param>
  152. /// <param name="e"></param>
  153. private void TurnOffValve(object sender, RoutedEventArgs e)
  154. {
  155. CheckOk = false;
  156. }
  157. /// <summary>
  158. /// mouse click
  159. /// </summary>
  160. /// <param name="sender"></param>
  161. /// <param name="e"></param>
  162. private void MouseButtonDown(object sender, MouseButtonEventArgs e)
  163. {
  164. if (!IsManualMode)
  165. return;
  166. }
  167. }
  168. }