终端一体化运控平台
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 

138 wiersze
6.2 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Data;
  10. using System.Windows.Documents;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Animation;
  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. /// ConveyorBelt.xaml 的交互逻辑
  21. /// </summary>
  22. public partial class ConveyorBelt : UserControl
  23. {
  24. public ConveyorBelt()
  25. {
  26. InitializeComponent();
  27. this.SizeChanged += ConveyorBelt_SizeChanged;
  28. }
  29. private void ConveyorBelt_SizeChanged(object sender, SizeChangedEventArgs e)
  30. {
  31. //传送带外边框绘制
  32. PathGeometry geometry = new PathGeometry();
  33. PathFigure pathFigure = new PathFigure();
  34. pathFigure.StartPoint = new Point(this.Height / 2, 0);
  35. pathFigure.Segments.Add(new ArcSegment(new Point(this.Height / 2, this.Height), new Size(this.Height / 2, this.Height / 2), 0, false, SweepDirection.Counterclockwise, true));
  36. pathFigure.Segments.Add(new LineSegment(new Point(this.Width, this.Height), true));
  37. pathFigure.Segments.Add(new LineSegment(new Point(this.Width, this.Height - ConveyorBeltWidth), true));
  38. double innerCircle = (this.Height - (ConveyorBeltWidth * 2)) / 2;//内圆半径
  39. pathFigure.Segments.Add(new LineSegment(new Point(ConveyorBeltWidth + innerCircle, this.Height - ConveyorBeltWidth), true));
  40. pathFigure.Segments.Add(new ArcSegment(new Point(ConveyorBeltWidth + innerCircle, ConveyorBeltWidth), new Size(innerCircle, innerCircle), 0, false, SweepDirection.Clockwise, true));
  41. pathFigure.Segments.Add(new LineSegment(new Point(this.Width, ConveyorBeltWidth), true));
  42. pathFigure.Segments.Add(new LineSegment(new Point(this.Width, 0), true));
  43. pathFigure.Segments.Add(new LineSegment(new Point(this.Height / 2, 0), true));
  44. geometry.Figures.Add(pathFigure);
  45. this.cb.Data = geometry;
  46. //传送带内部皮带绘制
  47. PathGeometry geometry1 = new PathGeometry();
  48. PathFigure pathFigure1 = new PathFigure();
  49. pathFigure1.StartPoint = new Point(this.Width, ConveyorBeltWidth / 2);
  50. double innerCircle1 = (this.Height - ConveyorBeltWidth) / 2;//内圆半径
  51. pathFigure1.Segments.Add(new LineSegment(new Point(innerCircle1 + ConveyorBeltWidth / 2, ConveyorBeltWidth / 2), true));
  52. pathFigure1.Segments.Add(new ArcSegment(new Point(innerCircle1 + ConveyorBeltWidth / 2, this.Height - ConveyorBeltWidth / 2), new Size(innerCircle1, innerCircle1), 0, false, SweepDirection.Counterclockwise, true));
  53. pathFigure1.Segments.Add(new LineSegment(new Point(this.Width, this.Height - ConveyorBeltWidth / 2), true));
  54. geometry1.Figures.Add(pathFigure1);
  55. this.mp.Data = geometry1;
  56. }
  57. private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  58. {
  59. (d as ConveyorBelt)?.Refursh();
  60. }
  61. private void Refursh()
  62. {
  63. if (Direction == 1) VisualStateManager.GoToState(this, "Left", false);
  64. else if (Direction == 2) VisualStateManager.GoToState(this, "Right", false);
  65. else VisualStateManager.GoToState(this, "Stop", false);
  66. }
  67. public DoubleCollection StrokeDashArray
  68. {
  69. get { return (DoubleCollection)GetValue(StrokeDashArrayProperty); }
  70. set { SetValue(StrokeDashArrayProperty, value); }
  71. }
  72. public static readonly DependencyProperty StrokeDashArrayProperty =
  73. DependencyProperty.Register("StrokeDashArray", typeof(DoubleCollection), typeof(ConveyorBelt),
  74. new PropertyMetadata(default, new PropertyChangedCallback(OnPropertyChanged)));
  75. public double ConveyorBeltWidth
  76. {
  77. get { return (double)GetValue(ConveyorBeltWidthProperty); }
  78. set { SetValue(ConveyorBeltWidthProperty, value); }
  79. }
  80. public static readonly DependencyProperty ConveyorBeltWidthProperty =
  81. DependencyProperty.Register("ConveyorBeltWidth", typeof(double), typeof(ConveyorBelt),
  82. new PropertyMetadata(50.0, new PropertyChangedCallback(OnPropertyChanged)));
  83. public Brush StrokeFillBrush
  84. {
  85. get { return (Brush)GetValue(StrokeFillBrushProperty); }
  86. set { SetValue(StrokeFillBrushProperty, value); }
  87. }
  88. public static readonly DependencyProperty StrokeFillBrushProperty =
  89. DependencyProperty.Register("StrokeFillBrush", typeof(Brush), typeof(ConveyorBelt),
  90. new PropertyMetadata(Brushes.LightBlue, new PropertyChangedCallback(OnPropertyChanged)));
  91. public Brush StrokeBrush
  92. {
  93. get { return (Brush)GetValue(StrokeBrushProperty); }
  94. set { SetValue(StrokeBrushProperty, value); }
  95. }
  96. public static readonly DependencyProperty StrokeBrushProperty =
  97. DependencyProperty.Register("StrokeBrush", typeof(Brush), typeof(ConveyorBelt),
  98. new PropertyMetadata(Brushes.LightBlue, new PropertyChangedCallback(OnPropertyChanged)));
  99. public double StrokeThickness
  100. {
  101. get { return (double)GetValue(StrokeThicknessProperty); }
  102. set { SetValue(StrokeThicknessProperty, value); }
  103. }
  104. public static readonly DependencyProperty StrokeThicknessProperty =
  105. DependencyProperty.Register("StrokeThickness", typeof(double), typeof(ConveyorBelt),
  106. new PropertyMetadata(1.0, new PropertyChangedCallback(OnPropertyChanged)));
  107. public int Direction
  108. {
  109. get { return (int)GetValue(DirectionProperty); }
  110. set { SetValue(DirectionProperty, value); }
  111. }
  112. public static readonly DependencyProperty DirectionProperty =
  113. DependencyProperty.Register("Direction", typeof(int), typeof(ConveyorBelt),
  114. new PropertyMetadata(0, new PropertyChangedCallback(OnPropertyChanged)));
  115. }
  116. }