방법: 스토리보드가 시작되면 이벤트 트리거를 사용하여 제어How to: Use Event Triggers to Control a Storyboard After It Starts

이 예제에서는가 시작 된 후 Storyboard 을 제어 하는 방법을 보여 줍니다.This example shows how to control a Storyboard after it starts. 를 사용 Storyboard XAMLXAML하 여를 시작 하려면 BeginStoryboard애니메이션을 적용 하는 개체 및 속성에 애니메이션을 배포한 다음 storyboard를 시작 하는를 사용 합니다.To start a Storyboard by using XAMLXAML, use BeginStoryboard, which distributes the animations to the objects and properties they animate and then starts the storyboard. 속성을Name 지정 하 여 이름을 지정 하면 제어 가능한 storyboard로 설정 됩니다. BeginStoryboardIf you give BeginStoryboard a name by specifying its Name property, you make it a controllable storyboard. 그런 다음 스토리 보드를 시작한 후 대화형으로 제어할 수 있습니다.You can then interactively control the storyboard after it starts.

다음 스토리 보드 작업을 개체와 EventTrigger 함께 사용 하 여 스토리 보드를 제어 합니다.Use the following storyboard actions together with EventTrigger objects to control a storyboard.

예제Example

다음 예제에서는 제어 가능한 storyboard 작업을 사용 하 여 스토리 보드를 대화형으로 제어 합니다.The following example uses controllable storyboard actions to interactively control a storyboard.

참고

코드를 사용 하 여 스토리 보드를 제어 하는 예제를 보려면 대화형 메서드를 사용 하 여 시작 된 후 Storyboard 제어를 참조 하세요.To see an example of controlling a storyboard by using code, see Control a Storyboard After It Starts Using Its Interactive Methods.

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  WindowTitle="Controlling a Storyboard" >
  <StackPanel Margin="20" >

    <!-- This rectangle is animated. -->
    <Rectangle Name="myRectangle"
      Width="100" Height="20" Margin="12,0,0,5" Fill="#AA3333FF" HorizontalAlignment="Left" />

    <!-- This StackPanel contains all the Buttons. -->
    <StackPanel Orientation="Horizontal" Margin="0,30,0,0">

      <Button Name="BeginButton">Begin</Button>
      <Button Name="PauseButton">Pause</Button>
      <Button Name="ResumeButton">Resume</Button>
      <Button Name="SeekButton">Seek</Button>
      <Button Name="SkipToFillButton">Skip To Fill</Button>
      <Button Name="SetSpeedRatioButton">Triple Speed</Button>
      <Button Name="StopButton">Stop</Button>

      <StackPanel.Triggers>
        
        <!-- Begin the Storyboard -->
        <EventTrigger RoutedEvent="Button.Click" SourceName="BeginButton">
          <BeginStoryboard Name="MyBeginStoryboard">
            <Storyboard >
              <DoubleAnimation 
                Storyboard.TargetName="myRectangle" 
                Storyboard.TargetProperty="Width" 
                Duration="0:0:5" From="100" To="500" />
            </Storyboard>
          </BeginStoryboard>
        </EventTrigger>

        <!-- Pause the Storyboard -->
        <EventTrigger RoutedEvent="Button.Click" SourceName="PauseButton">
          <PauseStoryboard BeginStoryboardName="MyBeginStoryboard" />
        </EventTrigger>

        <!-- Resume the Storyboard -->
        <EventTrigger RoutedEvent="Button.Click" SourceName="ResumeButton">
          <ResumeStoryboard BeginStoryboardName="MyBeginStoryboard" />
        </EventTrigger>
 
         <!-- Seek one second into the storyboard's active period. -->
         <EventTrigger RoutedEvent="Button.Click" SourceName="SeekButton">
           <SeekStoryboard 
            BeginStoryboardName="MyBeginStoryboard" 
            Offset="0:0:1" Origin="BeginTime" />
        </EventTrigger>   

        <!-- Skip to Fill -->
        <EventTrigger RoutedEvent="Button.Click" SourceName="SkipToFillButton">
          <SkipStoryboardToFill BeginStoryboardName="MyBeginStoryboard" />
        </EventTrigger>

        <!-- Stop the Storyboard -->
        <EventTrigger RoutedEvent="Button.Click" SourceName="StopButton">
          <StopStoryboard BeginStoryboardName="MyBeginStoryboard" />
        </EventTrigger>
        
        <!-- Triple the speed of the Storyboard -->
        <EventTrigger RoutedEvent="Button.Click" SourceName="SetSpeedRatioButton">
          <SetStoryboardSpeedRatio SpeedRatio="3" BeginStoryboardName="MyBeginStoryboard" />
        </EventTrigger>
      </StackPanel.Triggers>
    </StackPanel>
  </StackPanel>
</Page>

추가 예제는 애니메이션 예제 갤러리를 참조 하세요.For additional examples, see the Animation Example Gallery.

참고자료See also