tags:

views:

26

answers:

1

I have a MediaElement where the source is bound to some data

<MediaElement Source='{Binding Something}' />

What is the simplest way to have the video repeat? Ideally, MediaElement would have a repeat behavior property.

<MediaElement RepeatBehavior='Forever' ... />

But I can't find such a property.

A: 

You need to add a Storyboard to the MediaElement. See the example below:

<MediaElement Name="myMediaElement" >
      <MediaElement.Triggers>
        <EventTrigger RoutedEvent="MediaElement.Loaded">
          <EventTrigger.Actions>
            <BeginStoryboard>
              <Storyboard>

                <!-- The MediaTimeline has a RepeatBehavior="Forever" which makes the media play
                     over and over indefinitely.-->
                <MediaTimeline Source="media\tada.wav" Storyboard.TargetName="myMediaElement"  
                 RepeatBehavior="Forever" />

              </Storyboard>
            </BeginStoryboard>
          </EventTrigger.Actions>
        </EventTrigger>
      </MediaElement.Triggers>
    </MediaElement>
Wouter Janssens - Xelos bvba