This documentation is archived and is not being maintained.

How to: Trigger Media Playback with a User Event

This example shows how to synchronize media playback with an event.


The following example uses the MediaElement control and the MediaTimeline class to play a sound that occurs when the user clicks a Button.

<Page xmlns=""
  xmlns:x="" >

    <!-- The MediaElement control plays the sound. -->
    <MediaElement Name="myMediaElement" />

    <Button>Click to Hear a Sound!
        <EventTrigger RoutedEvent="Button.Click">

                <!-- Sound wave from this source is played when the button is clicked.-->
                <MediaTimeline Source="C:\WINDOWS\Media\ringin.wav" Storyboard.TargetName="myMediaElement"  />



For the complete sample, see Media Gallery.

See Also