The following example shows how to remove a Storyboard to stop it from continuing when the user navigates away from the page containing the Storyboard.
<!-- The MediaElement control plays the sound. -->
<MediaElement Name="myMediaElement" />
<!-- This trigger causes the Storyboard to start (the music start) when you click the
"BeginButton" button. -->
<EventTrigger RoutedEvent="Button.Click" SourceName="BeginButton">
<MediaTimeline Source="C:\WINDOWS\Media\town.mid" Storyboard.TargetName="myMediaElement"
<!-- 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" >
<RemoveStoryboard BeginStoryboardName="myBeginStoryboard" />