Nasıl yapılır: Kullanıcı Olayı ile Medya Yürütme Tetikleme

Bu örnek, bir olayla birlikte medya kayıttan yürütmeyi eşitlemeyi gösterir.

Örnek

Aşağıdaki örnek, MediaElementMediaTimeline Kullanıcı bir tıkladığı zaman oluşan bir sesi oynatmak için denetimini ve sınıfını kullanır Button .

<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" />

    <Button>Click to Hear a Sound!
      <Button.Triggers>
        <EventTrigger RoutedEvent="Button.Click">
          <EventTrigger.Actions>
            <BeginStoryboard>
              <Storyboard>

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

              </Storyboard>
            </BeginStoryboard>
          </EventTrigger.Actions>
        </EventTrigger>
      </Button.Triggers>
    </Button>

  </StackPanel>
</Page>

Ayrıca bkz.