以下是C#代码
CODE:C# Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace slArrow
{
public partial class Page : UserControl
{
public Page()
{
InitializeComponent();
LayoutRoot.Loaded += new RoutedEventHandler(LayoutRoot_Loaded);
}
void LayoutRoot_Loaded(object sender, RoutedEventArgs e)
{
drawArrow(new Point(300, 300));
}
public void drawArrow(Point endP)
{
double slopy;
double cosy;
double siny;
double Par = 8.0;
//slopy = Math.atan2((StartP.y-endP.y+20),(StartP.x-endP.x));
slopy=3.1415926;
cosy = Math.Cos(slopy);
siny = Math.Sin(slopy);
PathGeometry aPathGeometry = new PathGeometry();
arrowPath.Data = aPathGeometry;
aPathGeometry.Figures = new PathFigureCollection();
PathFigure aPathFigure = new PathFigure();
aPathFigure.StartPoint = endP;
LineSegment Line1 = new LineSegment();
LineSegment Line2 = new LineSegment();
LineSegment Line3 = new LineSegment();
Point p1 = new Point();
Point p2 = new Point();
Point p3 = new Point();
p1.X = endP.X + ( Par * cosy - ( Par / 2.0 * siny ) );
p1.Y = endP.Y + ( Par * siny + ( Par / 2.0 * cosy ) );
p2.X = endP.X + ( Par * cosy + Par / 2.0 * siny );
p2.Y = endP.Y - ( Par / 2.0 * cosy - Par * siny );
p3.X = endP.X;
p3.Y = endP.Y;
Line1.Point = p1;
Line2.Point = p2;
Line3.Point = p3;
aPathFigure.Segments.Add(Line1);
aPathFigure.Segments.Add(Line2);
aPathFigure.Segments.Add(Line3);
aPathGeometry.Figures.Add(aPathFigure);
}
}
}
以下代码放在XAML文档里边
CODE:XAML Code
<UserControl x:Class="slArrow.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300">
<Grid x:Name="LayoutRoot" Background="White">
<Path x:Name="arrowPath" Stroke="Red" StrokeThickness="4"/>
</Grid>
</UserControl>