private void DrawLine(Point p1, Point p2)
{
var line = new Line();
line.Stroke = Brushes.Red;
line.StrokeThickness = 2;
line.X1 = p1.X;
line.Y1 = p1.Y;
line.X2 = p2.X;
line.Y2 = p2.Y;
this.CanvasPaintPath.Children.Add(line);
var headlen = 10;//箭头线的长度
var theta = 45;//箭头线与直线的夹角,45°
double arrowX, arrowY;//箭头线终点坐标
// 计算各角度和对应的箭头终点坐标
var angle = Math.Atan2(p1.Y - p2.Y, p1.X - p2.X) * 180 / Math.PI;
var angle1 = (angle + theta) * Math.PI / 180;
var angle2 = (angle - theta) * Math.PI / 180;
var topX = headlen * Math.Cos(angle1);
var topY = headlen * Math.Sin(angle1);
var botX = headlen * Math.Cos(angle2);
var botY = headlen * Math.Sin(angle2);
arrowX = p2.X + topX;
arrowY = p2.Y + topY;
var line2 = new Line();
line2.Stroke = Brushes.Red;
line2.StrokeThickness = 2;
line2.X1 = arrowX;
line2.Y1 = arrowY;
line2.X2 = p2.X;
line2.Y2 = p2.Y;
this.CanvasPaintPath.Children.Add(line2);
arrowX = p2.X + botX;
arrowY = p2.Y + botY;
var line3 = new Line();
line3.Stroke = Brushes.Red;
line3.StrokeThickness = 2;
line3.X1 = arrowX;
line3.Y1 = arrowY;
line3.X2 = p2.X;
line3.Y2 = p2.Y;
this.CanvasPaintPath.Children.Add(line3);
}