Class MainWindowクラスの全コード
Imports System.Windows.Media.Animation
Class MainWindow
Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click
Dim myEllipse = New Ellipse()
myEllipse.HorizontalAlignment = Windows.HorizontalAlignment.Left
myEllipse.VerticalAlignment = Windows.VerticalAlignment.Top
myEllipse.Stroke = Brushes.Aquamarine
myEllipse.Width = 20
myEllipse.Height = 20
myEllipse.Fill = Brushes.Coral
Canvas1.Children.Add(myEllipse)
Dim myDoubleAnimation1 As DoubleAnimation = New DoubleAnimation
myDoubleAnimation1.From = "-10"
myDoubleAnimation1.To = "390"
Dim duration1 As Duration = New Duration(TimeSpan.FromSeconds(0.3))
myDoubleAnimation1.Duration = duration1
myDoubleAnimation1.AutoReverse = True
myDoubleAnimation1.RepeatBehavior = RepeatBehavior.Forever
Storyboard1.Children.Add(myDoubleAnimation1)
Storyboard.SetTargetProperty(myDoubleAnimation1, New PropertyPath("(Canvas.Left)"))
Storyboard.SetTarget(myDoubleAnimation1, myEllipse)
Dim myDoubleAnimation2 As DoubleAnimation = New DoubleAnimation
myDoubleAnimation2.From = "-10"
myDoubleAnimation2.To = "290"
Dim duration2 As Duration = New Duration(TimeSpan.FromSeconds(0.5))
myDoubleAnimation2.Duration = duration2
myDoubleAnimation2.AutoReverse = True
myDoubleAnimation2.RepeatBehavior = RepeatBehavior.Forever
Storyboard1.Children.Add(myDoubleAnimation2)
Storyboard.SetTargetProperty(myDoubleAnimation2, New PropertyPath("(Canvas.Top)"))
Storyboard.SetTarget(myDoubleAnimation2, myEllipse)
Storyboard1.Begin()
End Sub
Private Sub Button2_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button2.Click
Storyboard1.Stop()
End Sub
End Class