Re: Drawing straight line
Hope I'm reading what you want correctly.
Code:
<Line x:Name="myLine" Stroke="Black" Fill="Black" StrokeThickness="2" StrokeDashArray="2,2" />
Code:
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()
Re: Drawing straight line
Reread the question and decided you're looking to have the line appear to move rather than animating the drawing of the line.
Code:
<Line x:Name="myLine" X1="100" Y1="100" X2="400" Y2="150" Stroke="Black" Fill="Black" StrokeThickness="2" StrokeDashArray="2,2" />
Code:
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.