Note that there are some explanatory texts on larger screens.

plurals
  1. POProgrammatically reverse Storyboard
    text
    copied!<p>I have the following storyboard:</p> <pre><code>&lt;Window.Resources&gt; &lt;Storyboard x:Key="ButtonsAnim"&gt; &lt;DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="topRightButton" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)"&gt; &lt;SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/&gt; &lt;SplineDoubleKeyFrame KeyTime="00:00:00.2000000" Value="-100"/&gt; &lt;/DoubleAnimationUsingKeyFrames&gt; &lt;DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="topRightButton" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)"&gt; &lt;SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/&gt; &lt;SplineDoubleKeyFrame KeyTime="00:00:00.2000000" Value="100"/&gt; ... </code></pre> <p>It basically moves some buttons around in a canvas.</p> <p>This is the code that starts the animation:</p> <pre><code>void MainWindow_Loaded(object sender, RoutedEventArgs e) { Storyboard sb = (Storyboard)Resources["ButtonsAnim"]; storyBoard = sb; storyBoard.Begin(this, true); } </code></pre> <p>What I am trying to do is to reset the animation when I click a button which hides the window. When the window reappears the animation should start from the beginning.</p> <p>I tried using storyBoard.Begin(this, true) when the application reappears but for this first milliseconds the buttons are at their last position.</p> <p>I then tried storyBoard.seek(TimeSpan.Zero) before hiding the window but it fails:</p> <blockquote> <p>System.Windows.Media.Animation Warning: 6 : Unable to perform action because the specified Storyboard was never applied to this object for interactive control.; Action='Seek'; Storyboard='System.Windows.Media.Animation.Storyboard'; Storyboard.HashCode='24901833'; Storyboard.Type='System.Windows.Media.Animation.Storyboard'; TargetElement='System.Windows.Media.Animation.Storyboard'; TargetElement.HashCode='24901833'; TargetElement.Type='System.Windows.Media.Animation.Storyboard'</p> </blockquote> <p>I also tried storyBoard.remove(this) before hiding the window, same effect: the buttons are at their last position.</p> <p>Any ideas?</p> <p>Thank you.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload