Wpf Animation: Programmatically Begin Storyboard

The following c# code example shows how to create an interactive controllable wpf storyboard using a MediaElement and MediaTimeline animation.

NameScope.SetNameScope(this, new NameScope());
MediaTimeline _audioTimeline = new MediaTimeline(“c:\temp\AudioFile.mp3”);
MediaElement _audioMediaElement = new MediaElement();
_audioMediaElement.Name = “audioMediaElement”;
RegisterName(_audioMediaElement.Name, _audioMediaElement);

_audioMediaElement.LoadedBehavior = MediaState.Manual;
_audioMediaElement.UnloadedBehavior = MediaState.Manual;

Storyboard.SetTargetName(_audioTimeline, _audioMediaElement.Name);

Storyboard _packageStoryBoard = new Storyboard();
_packageStoryBoard.SlipBehavior = SlipBehavior.Slip;

Also see How to: Control a MediaElement by Using a Storyboard in XAML


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: