In this post, I will discuss how to create a Silverlight arrow. This will be beneficial for implementing Silverlight presentation where you can add some arrows to point to some blocks. This is simple enough to implement & will be beneficial for beginners.
Create a Silverlight project. Now add a
public class “
Arrow” in it. Inside the Arrow.cs, you have to add three lines (one is the base line, the second is the left arrow head & the third is the right arrow head). Next you have to add those three lines inside a
Let’s start with creating the simple arrow in a step-by-step process. The first step is to create the base line of the arrow. Create a
Line and set its (x1, y1) & (x2, y2). This will create the line.
private static Line CreateBaseLine
(double startX, double startY, double length, Brush lineBrush, double thickness)
Line arrowLine = new Line();
arrowLine.Stroke = lineBrush;
arrowLine.StrokeThickness = thickness;
arrowLine.X1 = startX;
arrowLine.X2 = length;
arrowLine.Y1 = startY;
arrowLine.Y2 = startY;
Now let's create the left arrow head. The approach to it is the same as creating the base line. Here only you have to pass the instance of the base line for calculating the (x1, y1).
private static Line CreateLeftArrowHead(Brush lineBrush, double thickness, Line arrowLine)
Line arrowLeft = new Line();
arrowLeft.Stroke = lineBrush;
arrowLeft.StrokeThickness = thickness;
arrowLeft.X1 = arrowLine.X2 - 10.00;
arrowLeft.X2 = arrowLine.X2;
arrowLeft.Y1 = arrowLine.Y2 - 10.00;
arrowLeft.Y2 = arrowLine.Y2;
Creation of right arrow head is also similar to the one I mentioned for creating the left arrow head. The difference here is the y1.
private static Line CreateRightArrowHead
(Brush lineBrush, double thickness, Line arrowLine)
Line arrowRight = new Line();
arrowRight.Stroke = lineBrush;
arrowRight.StrokeThickness = thickness;
arrowRight.X1 = arrowLine.X2 - 10.00;
arrowRight.X2 = arrowLine.X2;
arrowRight.Y1 = arrowLine.Y2 + 10.00;
arrowRight.Y2 = arrowLine.Y2;
Here instead of creating two separate methods for creating the two arrow heads, you can just create only one method & pass the calculated (x1, y1) & (x2, y2). This is the simple approach mentioned here to give an idea to the beginner to create an arrow. It can be modified to implement some complex arrows like Horizontal, Vertical or even better Connected Arrows.