A trigger action that removes a Storyboard.
public ref class RemoveStoryboard sealed : System::Windows::Media::Animation::ControllableStoryboardAction
public sealed class RemoveStoryboard : System.Windows.Media.Animation.ControllableStoryboardAction
type RemoveStoryboard = class inherit ControllableStoryboardAction
Public NotInheritable Class RemoveStoryboard Inherits ControllableStoryboardAction
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Name="RootPage"> <StackPanel> <!-- The MediaElement control plays the sound. --> <MediaElement Name="myMediaElement" /> <Button Name="BeginButton">Begin</Button> <StackPanel.Triggers> <!-- This trigger causes the Storyboard to start (the music start) when you click the "BeginButton" button. --> <EventTrigger RoutedEvent="Button.Click" SourceName="BeginButton"> <EventTrigger.Actions> <BeginStoryboard Name="myBeginStoryboard"> <Storyboard> <MediaTimeline Source="C:\WINDOWS\Media\town.mid" Storyboard.TargetName="myMediaElement" RepeatBehavior="Forever" /> </Storyboard> </BeginStoryboard> </EventTrigger.Actions> </EventTrigger> <!-- When this page unloads, like when you navigate away from the page, this trigger causes the Storyboard to be removed and the clock to stop. If you come back to this page and click the button to start the Storyboard, the music starts from the beginning. Alternatively, if you don't unload the Storyboard when you leave the page, the Storyboard does not stop while you're gone and when you navigate back to the page you hear the music continuing as though you had never left. --> <EventTrigger RoutedEvent="Page.Unloaded" > <EventTrigger.Actions> <RemoveStoryboard BeginStoryboardName="myBeginStoryboard" /> </EventTrigger.Actions> </EventTrigger> </StackPanel.Triggers> </StackPanel> </Page>
Pause, Resume, Stop, Remove, or Otherwise Control a Storyboard Interactively
To be able to pause, resume, remove, or otherwise control a Storyboard interactively, set the Name property of its BeginStoryboard and use a ControllableStoryboardAction object (such as PauseStoryboard, ResumeStoryboard, or StopStoryboard) to control it by referencing its Name. If the Name of BeginStoryboard is unspecified, the Storyboard cannot be interactively controlled after it is begun. See How to: Use Event Triggers to Control a Storyboard After It Starts for more information.
When to Remove Storyboards
You should use the RemoveStoryboard action to remove any storyboards begun with a HandoffBehavior of Compose. It's also a good idea to remove background animations when the object they animate is no longer being used. For example, if you apply an indefinitely repeating storyboard using an element's Loaded event, you should also create an EventTrigger that uses a RemoveStoryboard action to remove the storyboard on the element's Unloaded event.
|RemoveStoryboard() RemoveStoryboard() RemoveStoryboard() RemoveStoryboard()||
Initializes a new instance of the RemoveStoryboard class.
|BeginStoryboardName BeginStoryboardName BeginStoryboardName BeginStoryboardName||ControllableStoryboardAction)|
|DependencyObjectType DependencyObjectType DependencyObjectType DependencyObjectType||
Gets the DependencyObjectType that wraps the CLR type of this instance.(Inherited from DependencyObject)
|Dispatcher Dispatcher Dispatcher Dispatcher||DispatcherObject)|
|IsSealed IsSealed IsSealed IsSealed||
Gets a value that indicates whether this instance is currently sealed (read-only).(Inherited from DependencyObject)