How to hold animation when animation is launched in WPF?

For example, the translation transformation animation is running, I want to hold the animation, but not stop it, how to do it?

+3
source share
1 answer

To pause the animation correctly, you need to call the Begin () method from the code, for example Loadedan event handler (for example:) Window_Loaded, because - a quote from MSDN:

When you start a storyboard that has been paused, it seems to resume and restart. However, this is not what is actually happening. The Begin method actually replaces the unpublished version. Each time the Begin method is called, watch objects are created for storyboard. These watches are distributed according to the properties that they enliven. Therefore, when the Begin method is called again, it does not restart its clock; he replaces them with a new watch.

Example:

<Window.Resources>
    <Storyboard x:Key="SomeStoryboard">
        ...
    </Storyboard>
</Window.Resources>

In an event Loadedor something else:

MyStoryboard = (Storyboard)this.FindResource("SomeStoryboard");
MyStoryboard.Begin();

And in the button Pause:

private void ButtonPause_Click(object sender, RoutedEventArgs e)
{
    MyStoryboard.Pause();
}

For more information see

MSDN: Storyboard.Pause Method

+1
source

All Articles