操作說明:重複播放媒體
此範例顯示如何無限期地撥放,亦即,將媒體設定為不斷地重播。
範例
下列範例會使用 MediaElement 和 MediaTimeline,在 Storyboard 中以無限迴圈播放媒體剪輯。
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
<StackPanel>
<!-- The MediaElement control plays the sound. -->
<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>
</StackPanel>
</Page>