title: WPF starting animation from vb.net code giving error
body: <p>I'm trying to trigger an animation declared in the window's XAML file from the window's vb code when an event is raised (calling a function), like a window's "loaded" event.</p>
  
  <p>Here's how I declare the animation (as a storyboard):</p>
  
  <pre><code>Dim StartAnimation As Storyboard = DirectCast(FindName("ServiceOn"), Storyboard)
  Dim StopAnimation As Storyboard = DirectCast(FindName("ServiceOff"), Storyboard)
  </code></pre>
  
  <p>And here's the code for the function that is failing:</p>
  
  <pre><code>Public Function CheckStatus() As Boolean
      If sControl.Status = ServiceControllerStatus.Running Then
          Me.Button1.Content = "Stop"
          Button1.BeginStoryboard(StartAnimation, HandoffBehavior.Compose, isControllable:=False)
      ElseIf sControl.Status = ServiceControllerStatus.Stopped Then
          Me.Button1.Content = "Start"
          Button1.BeginStoryboard(StopAnimation, HandoffBehavior.Compose, isControllable:=False)
      End If
  End Function
  </code></pre>
  
  <p>The error that I'm getting is the following:</p>
  
  <blockquote>
    <p>"Value cannot be null. Parameter name: storyboard"</p>
  </blockquote>
  
  <p>It looks like it's missing something right after "Button1.BeginStoryboard(StartAnimation,...)</p>
  
  <p>Any ideas?</p>