CalculatePalletPos.xaml.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. using System;
  2. using System.Windows;
  3. using System.Windows.Controls;
  4. using System.Windows.Media;
  5. using System.Windows.Shapes;
  6. using TeamAAS_VP.ViewModels.Product;
  7. namespace TeamAAS_VP.Views.Product
  8. {
  9. /// <summary>
  10. /// Interaction logic for CalculatePalletPos
  11. /// </summary>
  12. public partial class CalculatePalletPos : UserControl
  13. {
  14. public CalculatePalletPos()
  15. {
  16. InitializeComponent();
  17. DrawXYCoordinateSystem();
  18. ((CalculatePalletPosViewModel)DataContext).NotificationEvent += CalculatePalletPos_NotificationEvent;
  19. }
  20. private void CalculatePalletPos_NotificationEvent(string arg1, double arg2)
  21. {
  22. SnackbarSeven.MessageQueue?.Enqueue(
  23. arg1,
  24. null,
  25. null,
  26. null,
  27. false,
  28. true,
  29. TimeSpan.FromSeconds(arg2));
  30. }
  31. private void DrawXYCoordinateSystem()
  32. {
  33. // 获取 Canvas 对象
  34. Canvas canvas = this.canvas;
  35. // 获取 Canvas 的宽度和高度
  36. double width = canvas.Width;
  37. double height = canvas.Height;
  38. // 创建画笔
  39. SolidColorBrush brush = new SolidColorBrush(Colors.Red);
  40. Pen pen = new Pen(brush, 1);
  41. // 绘制X轴
  42. Line xAxis = new Line();
  43. xAxis.Stroke = brush;
  44. xAxis.X1 = 5;
  45. xAxis.Y1 = height-5;
  46. xAxis.X2 = width - 10; // 减去箭头长度
  47. xAxis.Y2 = height-5;
  48. canvas.Children.Add(xAxis);
  49. // 绘制X轴箭头
  50. Polygon xAxisArrow = new Polygon();
  51. xAxisArrow.Stroke = brush;
  52. xAxisArrow.Fill = brush;
  53. xAxisArrow.Points = new PointCollection() { new Point(width - 10, height-5), new Point(width - 20, height - 10), new Point(width - 20, height) };
  54. canvas.Children.Add(xAxisArrow);
  55. // 添加X轴标签
  56. TextBlock xLabel = new TextBlock();
  57. xLabel.Text = "X(P1方向)";
  58. xLabel.Foreground = Brushes.Black;
  59. xLabel.FontSize = 12;
  60. xLabel.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
  61. Canvas.SetLeft(xLabel, width - xLabel.DesiredSize.Width - 20); // 调整位置
  62. Canvas.SetTop(xLabel, height - xLabel.DesiredSize.Height-10);
  63. canvas.Children.Add(xLabel);
  64. brush = new SolidColorBrush(Colors.Green);
  65. // 绘制Y轴
  66. Line yAxis = new Line();
  67. yAxis.Stroke = brush;
  68. yAxis.X1 = 5;
  69. yAxis.Y1 = height - 5;
  70. yAxis.X2 = 5;
  71. yAxis.Y2 = 5; // 减去箭头长度
  72. canvas.Children.Add(yAxis);
  73. // 绘制Y轴箭头
  74. Polygon yAxisArrow = new Polygon();
  75. yAxisArrow.Stroke = brush;
  76. yAxisArrow.Fill = brush;
  77. yAxisArrow.Points = new PointCollection() { new Point(5, 0), new Point(0, 10), new Point(10, 10) };
  78. canvas.Children.Add(yAxisArrow);
  79. // 添加Y轴标签
  80. TextBlock yLabel = new TextBlock();
  81. yLabel.Text = "Y(P2方向)";
  82. yLabel.Foreground = Brushes.Black;
  83. yLabel.FontSize = 12;
  84. yLabel.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
  85. Canvas.SetLeft(yLabel,20);
  86. Canvas.SetTop(yLabel, 20); // 调整位置
  87. canvas.Children.Add(yLabel);
  88. }
  89. }
  90. }