■ Storyboard 엘리먼트를 사용해 애니메이션을 제어하는 방법을 보여준다.
▶ 예제 코드 (XAML)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
<StackPanel> <TextBlock Margin="10" TextWrapping="Wrap"> This sample uses the Begin, Pause, Resume, and Stop methods to control an animation. </TextBlock> <Canvas> <Canvas.Resources> <Storyboard x:Name="storyboard"> <PointAnimation Storyboard.TargetName="ellipseGeometry" Storyboard.TargetProperty="Center" RepeatBehavior="Forever" Duration="0:0:5" From="20 200" To="400 100" /> </Storyboard> </Canvas.Resources> <Path Fill="Blue"> <Path.Data> <EllipseGeometry x:Name="ellipseGeometry" Center="20 200" RadiusX="15" RadiusY="15" /> </Path.Data> </Path> <StackPanel Canvas.Left="10" Canvas.Top="265" Orientation="Horizontal"> <Button Margin="2" Width="65" Height="30" Content="Begin" Click="beginButton_Click" /> <Button Margin="2" Width="65" Height="30" Content="Pause" Click="pauseButton_Click" /> <Button Margin="2" Width="65" Height="30" Content="Resume" Click="resumeButton_Click" /> <Button Margin="2" Width="65" Height="30" Content="Stop" Click="stopButton_Click" /> </StackPanel> </Canvas> </StackPanel> |
▶ 예제 코드 (C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
using System.Windows.Input; #region Begin 버튼 클릭시 처리하기 - beginButton_Click(sender, e) /// <summary> /// Begin 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void beginButton_Click(object sender, RoutedEventArgs e) { this.storyboard.Begin(); } #endregion #region Pause 버튼 클릭시 처리하기 - pauseButton_Click(sender, e) /// <summary> /// Pause 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void pauseButton_Click(object sender, RoutedEventArgs e) { this.storyboard.Pause(); } #endregion #region Resume 버튼 클릭시 처리하기 - resumeButton_Click(sender, e) /// <summary> /// Resume 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void resumeButton_Click(object sender, RoutedEventArgs e) { this.storyboard.Resume(); } #endregion #region Stop 버튼 클릭시 처리하기 - stopButton_Click(sender, e) /// <summary> /// Stop 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void stopButton_Click(object sender, RoutedEventArgs e) { this.storyboard.Stop(); } #endregion |