终端一体化运控平台
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 

160 lignes
6.3 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Runtime.CompilerServices;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Data;
  11. using System.Windows.Documents;
  12. using System.Windows.Input;
  13. using System.Windows.Media;
  14. using System.Windows.Media.Imaging;
  15. using System.Windows.Navigation;
  16. using System.Windows.Shapes;
  17. namespace BPASmartClient.CustomResource.UserControls
  18. {
  19. /// <summary>
  20. /// ConveyBelt2.xaml 的交互逻辑
  21. /// </summary>
  22. public partial class ConveyBelt2 : UserControl
  23. {
  24. public ConveyBelt2()
  25. {
  26. InitializeComponent();
  27. }
  28. [Category("运行状态")]
  29. public bool IsRun
  30. {
  31. get { return (bool)GetValue(IsRunProperty); }
  32. set { SetValue(IsRunProperty, value); }
  33. }
  34. public static readonly DependencyProperty IsRunProperty =
  35. DependencyProperty.Register("IsRun", typeof(bool), typeof(ConveyBelt2), new PropertyMetadata(default(bool), new PropertyChangedCallback(OnRunningChanged)));
  36. private static void OnRunningChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  37. {
  38. string status = "Stop";
  39. if ((bool)e.NewValue)
  40. {
  41. if ((d as ConveyBelt2)?.BeltDirection == 0)
  42. {
  43. VisualStateManager.GoToState(d as ConveyBelt2, "RightState", false);
  44. return;
  45. }
  46. else
  47. {
  48. VisualStateManager.GoToState(d as ConveyBelt2, "LeftState", false);
  49. return;
  50. }
  51. }
  52. VisualStateManager.GoToState(d as ConveyBelt2, status, false);
  53. //VisualStateManager.GoToState(d as ConveyBelt2, (bool)e.NewValue ? "RunState" : "Stop", false);
  54. }
  55. public double BeltWidth
  56. {
  57. get { return (double)GetValue(BeltWidthProperty); }
  58. set { SetValue(BeltWidthProperty, value); }
  59. }
  60. public static readonly DependencyProperty BeltWidthProperty =
  61. DependencyProperty.Register("BeltWidth", typeof(double), typeof(ConveyBelt2), new PropertyMetadata(default(double), new PropertyChangedCallback(OnPropertyChanged)));
  62. private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  63. {
  64. (d as ConveyBelt2)?.Refresh();
  65. }
  66. public void Refresh()
  67. {
  68. PathGeometry geometry = new PathGeometry();
  69. PathFigure pathFigure = new PathFigure();
  70. if (BeltHeight > 100)
  71. {
  72. pathFigure.StartPoint = new Point(0, 35 + (BeltHeight - 100) / 2);
  73. pathFigure.Segments.Add(new LineSegment(new Point(BeltWidth - 10, 35 + (BeltHeight - 100) / 2), true));
  74. }
  75. else
  76. {
  77. pathFigure.StartPoint = new Point(0, 35);
  78. pathFigure.Segments.Add(new LineSegment(new Point(BeltWidth - 10, 35), true));
  79. }
  80. geometry.Figures.Add(pathFigure);
  81. this.belt.Data = geometry;
  82. this.belt.StrokeDashOffset = BeltDashOffset;
  83. this.br.Width = BeltWidth;
  84. if (BeltHeight > 100)
  85. {
  86. this.recDown.Margin = new Thickness(0, BeltHeight - 20, 0, 0);
  87. }
  88. else
  89. {
  90. this.recDown.Margin = new Thickness(0, 80, 0, 0);
  91. }
  92. this.belt.StrokeThickness = BeltDashThickess;
  93. }
  94. public double BeltHeight
  95. {
  96. get { return (double)GetValue(BeltHeightProperty); }
  97. set { SetValue(BeltHeightProperty, value); }
  98. }
  99. public static readonly DependencyProperty BeltHeightProperty =
  100. DependencyProperty.Register("BeltHeight", typeof(double), typeof(ConveyBelt2), new PropertyMetadata(default(double), new PropertyChangedCallback(OnPropertyChanged)));
  101. public double BeltDashOffset
  102. {
  103. get { return (double)GetValue(BeltDashOffsetProperty); }
  104. set { SetValue(BeltDashOffsetProperty, value); }
  105. }
  106. public static readonly DependencyProperty BeltDashOffsetProperty =
  107. DependencyProperty.Register("BeltDashOffset", typeof(double), typeof(ConveyBelt2), new PropertyMetadata(default(double), new PropertyChangedCallback(OnPropertyChanged)));
  108. public double BeltDashThickess
  109. {
  110. get { return (double)GetValue(BeltDashThickessProperty); }
  111. set { SetValue(BeltDashThickessProperty, value); }
  112. }
  113. public static readonly DependencyProperty BeltDashThickessProperty =
  114. DependencyProperty.Register("BeltDashThickess", typeof(double), typeof(ConveyBelt2), new PropertyMetadata(default(double), new PropertyChangedCallback(OnPropertyChanged)));
  115. public int BeltDirection
  116. {
  117. get { return (int)GetValue(BeltDirectionProperty); }
  118. set { SetValue(BeltDirectionProperty, value); }
  119. }
  120. public static readonly DependencyProperty BeltDirectionProperty =
  121. DependencyProperty.Register("BeltDirection", typeof(int), typeof(ConveyBelt2), new PropertyMetadata(default(int), new PropertyChangedCallback(OnDirectionChanged)));
  122. private static void OnDirectionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  123. {
  124. string status = "Stop";
  125. if ((d as ConveyBelt2).IsRun)
  126. {
  127. if ((d as ConveyBelt2)?.BeltDirection == 0)
  128. {
  129. VisualStateManager.GoToState(d as ConveyBelt2, "RightState", false);
  130. return;
  131. }
  132. else
  133. {
  134. VisualStateManager.GoToState(d as ConveyBelt2, "LeftState", false);
  135. return;
  136. }
  137. }
  138. VisualStateManager.GoToState(d as ConveyBelt2, status, false);
  139. //if ((d as ConveyBelt2)?.BeltDirection == 0)
  140. //{
  141. // VisualStateManager.GoToState(d as ConveyBelt2, "RightState", false);
  142. //}
  143. //else
  144. //{
  145. // VisualStateManager.GoToState(d as ConveyBelt2, "LeftState", false);
  146. //}
  147. }
  148. }
  149. }