Click here to Skip to main content
11,583,859 members (63,704 online)
Click here to Skip to main content

Tagged as

How to create a Simple Arrow in Silverlight?

, 26 Jan 2010 CPOL 14.3K 5
Rate this:
Please Sign up or sign in to vote.
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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Kunal Chowdhury (@kunal2383)
Team Leader
India India
Kunal Chowdhury is a Microsoft "Windows Platform Development" MVP (Most Valuable Professional), a Codeproject Mentor, Telerik MVP, Nokia Developer Champion, 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
Facebook: http://facebook.com/blog.kunal
Twitter : http://twitter.com/kunal2383

You may also be interested in...

Comments and Discussions

 
GeneralMy vote of 2 Pin
Paul D'hertoghe1-Feb-10 23:39
memberPaul D'hertoghe1-Feb-10 23:39 
GeneralRe: My vote of 2 Pin
KunalChowdhury15-Feb-10 19:19
memberKunalChowdhury15-Feb-10 19:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150603.1 | Last Updated 26 Jan 2010
Article Copyright 2010 by Kunal Chowdhury (@kunal2383)
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid