终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

131 lines
5.2 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. VisualStateManager.GoToState(d as ConveyBelt2, (bool)e.NewValue ? "RunState" : "Stop", false);
  39. }
  40. public double BeltWidth
  41. {
  42. get { return (double)GetValue(BeltWidthProperty); }
  43. set { SetValue(BeltWidthProperty, value); }
  44. }
  45. public static readonly DependencyProperty BeltWidthProperty =
  46. DependencyProperty.Register("BeltWidth", typeof(double), typeof(ConveyBelt2), new PropertyMetadata(default(double), new PropertyChangedCallback(OnPropertyChanged)));
  47. private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  48. {
  49. (d as ConveyBelt2)?.Refresh();
  50. }
  51. public void Refresh()
  52. {
  53. PathGeometry geometry = new PathGeometry();
  54. PathFigure pathFigure = new PathFigure();
  55. if (BeltHeight > 100)
  56. {
  57. pathFigure.StartPoint = new Point(0, 35 + (BeltHeight - 100) / 2);
  58. pathFigure.Segments.Add(new LineSegment(new Point(BeltWidth - 10, 35 + (BeltHeight - 100)/2), true));
  59. }
  60. else
  61. {
  62. pathFigure.StartPoint = new Point(0, 35);
  63. pathFigure.Segments.Add(new LineSegment(new Point(BeltWidth - 10, 35), true));
  64. }
  65. geometry.Figures.Add(pathFigure);
  66. this.belt.Data = geometry;
  67. this.belt.StrokeDashOffset = BeltDashOffset;
  68. this.br.Width = BeltWidth;
  69. if (BeltHeight > 100)
  70. {
  71. this.recDown.Margin = new Thickness(0, BeltHeight - 20, 0, 0);
  72. }
  73. else
  74. {
  75. this.recDown.Margin = new Thickness(0, 80, 0, 0);
  76. }
  77. this.belt.StrokeThickness = BeltDashThickess;
  78. }
  79. public double BeltHeight
  80. {
  81. get { return (double)GetValue(BeltHeightProperty); }
  82. set { SetValue(BeltHeightProperty, value); }
  83. }
  84. public static readonly DependencyProperty BeltHeightProperty =
  85. DependencyProperty.Register("BeltHeight", typeof(double), typeof(ConveyBelt2), new PropertyMetadata(default(double), new PropertyChangedCallback(OnPropertyChanged)));
  86. public double BeltDashOffset
  87. {
  88. get { return (double)GetValue(BeltDashOffsetProperty); }
  89. set { SetValue(BeltDashOffsetProperty, value); }
  90. }
  91. public static readonly DependencyProperty BeltDashOffsetProperty =
  92. DependencyProperty.Register("BeltDashOffset", typeof(double), typeof(ConveyBelt2), new PropertyMetadata(default(double), new PropertyChangedCallback(OnPropertyChanged)));
  93. public double BeltDashThickess
  94. {
  95. get { return (double)GetValue(BeltDashThickessProperty); }
  96. set { SetValue(BeltDashThickessProperty, value); }
  97. }
  98. public static readonly DependencyProperty BeltDashThickessProperty =
  99. DependencyProperty.Register("BeltDashThickess", typeof(double), typeof(ConveyBelt2), new PropertyMetadata(default(double), new PropertyChangedCallback(OnPropertyChanged)));
  100. public int BeltDirection
  101. {
  102. get { return (int)GetValue(BeltDirectionProperty); }
  103. set { SetValue(BeltDirectionProperty, value); }
  104. }
  105. public static readonly DependencyProperty BeltDirectionProperty =
  106. DependencyProperty.Register("BeltDirection", typeof(int), typeof(ConveyBelt2), new PropertyMetadata(default(int), new PropertyChangedCallback(OnDirectionChanged)));
  107. private static void OnDirectionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  108. {
  109. if ((d as ConveyBelt2)?.BeltDirection == 0)
  110. {
  111. VisualStateManager.GoToState(d as ConveyBelt2, "RightState", false);
  112. }
  113. else
  114. {
  115. VisualStateManager.GoToState(d as ConveyBelt2, "LeftState", false);
  116. }
  117. }
  118. }
  119. }