# .NET and More > Silverlight >  Drawing straight line

## usamaalam

Hello everybody,

Is there a way to draw a straight line using available controls?  I need to draw dotted straight line between two points having drawing effect, means need to give a feel that the line is moving between two points.  I need to draw it dynamically by taking coordinates from the db.

Thanks.

----------


## MattP

Hope I'm reading what you want correctly.



```
<Line x:Name="myLine" Stroke="Black" Fill="Black" StrokeThickness="2" StrokeDashArray="2,2" />
```



```
        Dim p1 As New Point(100, 100)
        Dim p2 As New Point(200, 150)

        myLine.X1 = p1.X
        myLine.Y1 = p1.Y

        Dim sb As New Storyboard

        Dim xAnim As New DoubleAnimation
        xAnim.Duration = New Duration(TimeSpan.FromSeconds(2))
        xAnim.From = p1.X
        xAnim.To = p2.X
        Storyboard.SetTarget(xAnim, myLine)
        Storyboard.SetTargetProperty(xAnim, New PropertyPath(Line.X2Property))
        sb.Children.Add(xAnim)

        Dim yAnim As New DoubleAnimation
        yAnim.Duration = New Duration(TimeSpan.FromSeconds(2))
        yAnim.From = p1.Y
        yAnim.To = p2.Y
        Storyboard.SetTarget(yAnim, myLine)
        Storyboard.SetTargetProperty(yAnim, New PropertyPath(Line.Y2Property))
        sb.Children.Add(yAnim)

        sb.Begin()
```

----------


## MattP

Reread the question and decided you're looking to have the line appear to move rather than animating the drawing of the line.



```
<Line x:Name="myLine" X1="100" Y1="100" X2="400" Y2="150" Stroke="Black" Fill="Black" StrokeThickness="2" StrokeDashArray="2,2" />
```



```
        Dim sb As New Storyboard

        Dim offsetAnim As New DoubleAnimation
        offsetAnim.Duration = New Duration(TimeSpan.FromSeconds(0.5))
        offsetAnim.From = 4
        offsetAnim.To = 0
        offsetAnim.RepeatBehavior = System.Windows.Media.Animation.RepeatBehavior.Forever
        Storyboard.SetTarget(offsetAnim, myLine)
        Storyboard.SetTargetProperty(offsetAnim, New PropertyPath(Line.StrokeDashOffsetProperty))
        sb.Children.Add(offsetAnim)

        sb.Begin()
```

Swap the 'From' and 'To' values if you want it to move the other way.

----------

