| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- using System;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Media;
- using System.Windows.Shapes;
- using TeamAAS_VP.ViewModels.Product;
- namespace TeamAAS_VP.Views.Product
- {
- /// <summary>
- /// Interaction logic for CalculatePalletPos
- /// </summary>
- public partial class CalculatePalletPos : UserControl
- {
- public CalculatePalletPos()
- {
- InitializeComponent();
- DrawXYCoordinateSystem();
- ((CalculatePalletPosViewModel)DataContext).NotificationEvent += CalculatePalletPos_NotificationEvent;
- }
- private void CalculatePalletPos_NotificationEvent(string arg1, double arg2)
- {
- SnackbarSeven.MessageQueue?.Enqueue(
- arg1,
- null,
- null,
- null,
- false,
- true,
- TimeSpan.FromSeconds(arg2));
- }
- private void DrawXYCoordinateSystem()
- {
- // 获取 Canvas 对象
- Canvas canvas = this.canvas;
- // 获取 Canvas 的宽度和高度
- double width = canvas.Width;
- double height = canvas.Height;
- // 创建画笔
- SolidColorBrush brush = new SolidColorBrush(Colors.Red);
- Pen pen = new Pen(brush, 1);
- // 绘制X轴
- Line xAxis = new Line();
- xAxis.Stroke = brush;
- xAxis.X1 = 5;
- xAxis.Y1 = height-5;
- xAxis.X2 = width - 10; // 减去箭头长度
- xAxis.Y2 = height-5;
- canvas.Children.Add(xAxis);
- // 绘制X轴箭头
- Polygon xAxisArrow = new Polygon();
- xAxisArrow.Stroke = brush;
- xAxisArrow.Fill = brush;
- xAxisArrow.Points = new PointCollection() { new Point(width - 10, height-5), new Point(width - 20, height - 10), new Point(width - 20, height) };
- canvas.Children.Add(xAxisArrow);
- // 添加X轴标签
- TextBlock xLabel = new TextBlock();
- xLabel.Text = "X(P1方向)";
- xLabel.Foreground = Brushes.Black;
- xLabel.FontSize = 12;
- xLabel.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
- Canvas.SetLeft(xLabel, width - xLabel.DesiredSize.Width - 20); // 调整位置
- Canvas.SetTop(xLabel, height - xLabel.DesiredSize.Height-10);
- canvas.Children.Add(xLabel);
- brush = new SolidColorBrush(Colors.Green);
- // 绘制Y轴
- Line yAxis = new Line();
- yAxis.Stroke = brush;
- yAxis.X1 = 5;
- yAxis.Y1 = height - 5;
- yAxis.X2 = 5;
- yAxis.Y2 = 5; // 减去箭头长度
- canvas.Children.Add(yAxis);
- // 绘制Y轴箭头
- Polygon yAxisArrow = new Polygon();
- yAxisArrow.Stroke = brush;
- yAxisArrow.Fill = brush;
- yAxisArrow.Points = new PointCollection() { new Point(5, 0), new Point(0, 10), new Point(10, 10) };
- canvas.Children.Add(yAxisArrow);
- // 添加Y轴标签
- TextBlock yLabel = new TextBlock();
- yLabel.Text = "Y(P2方向)";
- yLabel.Foreground = Brushes.Black;
- yLabel.FontSize = 12;
- yLabel.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
- Canvas.SetLeft(yLabel,20);
- Canvas.SetTop(yLabel, 20); // 调整位置
- canvas.Children.Add(yLabel);
- }
- }
- }
|