13,046,773 members (40,787 online)
Technical Blog
alternative version

#### Stats

16.2K views
5 bookmarked
Posted 26 Jan 2010

# How to create a Simple Arrow in Silverlight?

, 26 Jan 2010
 Rate this:
In this post, I will discuss how to create a Silverlight arrow. This will be beneficial for implementing Silverlight presentations where you can add some arrows to point to some blocks. This is simple enough to implement & will be beneficial for beginners.

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 `Panel`.

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;
return arrowLine;
}```

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;
return arrowLeft;
}```

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;
return arrowRight;
}```

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.

## Share

 Software Developer (Senior) India
Kunal Chowdhury is a Microsoft "Windows Platform Development" MVP (Most Valuable Professional), a Codeproject Mentor, Telerik Developer Expert, Nokia Developer Champion, Windows 10 Champion, Microsoft Rockstar, Speaker in various Microsoft events, Author, passionate Blogger and a Software Engineer by profession.

He is currently working in an MNC located in India. He has a very good skill over XAML, C#, Silverlight, Windows Phone, WPF and Windows Store (WinRT) app development. He posts his findings, articles, tutorials in his technical blog and CodeProject.

Technical Blog: http://www.kunal-chowdhury.com

## You may also be interested in...

 Pro Pro

 First Prev Next
 My vote of 2 Paul D'hertoghe1-Feb-10 23:39 Paul D'hertoghe 1-Feb-10 23:39
 Re: My vote of 2 KunalChowdhury15-Feb-10 19:19 KunalChowdhury 15-Feb-10 19:19
 Last Visit: 31-Dec-99 18:00     Last Update: 23-Jul-17 20:00 Refresh 1