XAML Line

The element of XAML is used to draw a line. This article shows how to use the Line element to draw lines in XAML.
  • 5146
The <Line/> element of XAML is used to draw a line. The X1,Y1 and X2,Y2 attributes represent the starting and ending point of the line and Stroke represents the color of the line. The StrokeThickness attribute represents the thickness of the line.

The following code draws a line from point (100,100) t (300,100) with blue color and thickness is 5.

 

<Grid x:Name="LayoutRoot" Background="#FFE4EDE1">

        <Line Stroke="#000fff" StrokeThickness="5" X1="100" Y1="100" X2="300" Y2="100" >  

        </Line>

      </Grid>

The output looks like Figure 1.

 DrawingGraphicsObjectsImg1.gif 

Figure 1. Drawing a line

A line can have start and end caps, which can be in a round, trianble, square, and flat ends. The StrokeStartLineCap and StrokeEndLineCap attributes of Line tag is used to set line caps. The following code sets StartLineCap as a triangle and EndLineCap as a round shape.

 

<Grid x:Name="LayoutRoot" Background="#FFE4EDE1">

        <Line Stroke="#000fff" StrokeThickness="5" X1="100" Y1="100" X2="300" Y2="100"

              StrokeStartLineCap="Triangle" StrokeEndLineCap="Round" StrokeDashCap="Square"  >  

        </Line>

      </Grid>


Further Readings|

You may also want to read these related articles.
Ask Your Question 
 
Got a programming related question? You may want to post your question here
 

 

 

 

© 2020 DotNetHeaven. All rights reserved.