title: Using data binding to launch animations in WPF
body: <p>I am trying to adapt a simple WPF application to use the Model-View-ViewModel pattern. On my page I have a couple of animations:</p>
  
  <pre><code>&lt;Page.Resources&gt;
      &lt;Storyboard x:Name="storyboardRight"
                  x:Key="storyboardRight"&gt;
          &lt;DoubleAnimation x:Name="da3"
                           Storyboard.TargetName="labelRight"
                           Storyboard.TargetProperty="Opacity"
                           From="0"
                           To="1"
                           Duration="0:0:0.5" /&gt;
          &lt;DoubleAnimation x:Name="da4"
                           Storyboard.TargetName="labelRight"
                           Storyboard.TargetProperty="Opacity"
                           From="1"
                           To="0"
                           BeginTime="0:0:1"
                           Duration="0:0:0.5" /&gt;
      &lt;/Storyboard&gt;
      ...
  &lt;/Page.Resources&gt;
  </code></pre>
  
  <p>Currently I begin the animation in the code behind, and can listen to the Completed event to do something when it finishes with the following code:</p>
  
  <pre><code>storyboardRight = (Storyboard)TryFindResource("storyboardRight");
  storyboardRight.Completed += new EventHandler(storyboardRight_Completed);
  storyboardRight.Begin(this);
  </code></pre>
  
  <p>Is there a way of data binding the storyboard to my ViewModel so that it starts on an event raised by the ViewModel and can call-back into that ViewModel when it is finished?</p>