첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
본 블로그는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 블로그 콘텐츠 향상을 위해 쓰여집니다.

728x90
반응형
728x170

TestProject.zip
다운로드

▶ MainWindow.xaml

<Window x:Class="TestProject.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Width="800"
    Height="600"
    Title="Storyboard 클래스 : Begin/Pause/Resume/SkipToFill/SetSpeedRatio/Stop 메소드 사용하기"
    FontFamily="나눔고딕코딩"
    FontSize="16">
    <Grid>
        <StackPanel
            HorizontalAlignment="Center"
            VerticalAlignment="Center">
            <Rectangle Name="rectangle"
                Width="100"
                Height="100"
                Fill="Blue" />
            <StackPanel
                Margin="10"
                Orientation="Horizontal">
                <Button Name="beginButton"
                    Margin="5"
                    Padding="10"
                    Content="Begin" />
                <Button Name="pauseButton"
                    Margin="5"
                    Padding="10"
                    Content="Pause" />
                <Button Name="resumeButton"
                    Margin="5"
                    Padding="10"
                    Content="Resume" />
                <Button Name="skipToFillButton"
                    Margin="5"
                    Padding="10"
                    Content="Skip to Fill" />
                <Button Name="tripleSpeedButton"
                    Margin="5"
                    Padding="10"
                    Content="Triple Speed" />
                <Button Name="stopButton"
                    Margin="5"
                    Padding="10"
                    Content="Stop" />
            </StackPanel>
        </StackPanel>
    </Grid>
</Window>

 

728x90

 

▶ MainWindow.xaml.cs

using System;
using System.Windows;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace TestProject
{
    /// <summary>
    /// 메인 윈도우
    /// </summary>
    public partial class MainWindow : Window
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Field
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region Field

        /// <summary>
        /// 스토리 보드
        /// </summary>
        private Storyboard storyboard;

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - MainWindow()

        /// <summary>
        /// 생성자
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();

            this.storyboard = new Storyboard();

            DoubleAnimation doubleAnimation = new DoubleAnimation();

            doubleAnimation.From        = 1.0;
            doubleAnimation.To          = 0.0;
            doubleAnimation.Duration    = new Duration(TimeSpan.FromMilliseconds(5000));

            Storyboard.SetTargetName    (doubleAnimation, this.rectangle.Name);
            Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath(Rectangle.OpacityProperty));

            this.storyboard.Children.Add(doubleAnimation);

            this.beginButton.Click       += beginButton_Click;
            this.pauseButton.Click       += pauseButton_Click;
            this.resumeButton.Click      += resumeButton_Click;
            this.skipToFillButton.Click  += skipToFillButton_Click;
            this.tripleSpeedButton.Click += tripleSpeedButton_Click;
            this.stopButton.Click        += stopButton_Click;
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #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(this, true);
        }

        #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(this);
        }

        #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(this);
        }

        #endregion
        #region Skip to Fill 버튼 클릭시 처리하기 - skipToFillButton_Click(sender, e)

        /// <summary>
        /// Skip to Fill 버튼 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void skipToFillButton_Click(object sender, RoutedEventArgs e)
        {
            this.storyboard.SkipToFill(this);
        }

        #endregion
        #region Triple Speed 버튼 클릭시 처리하기 - tripleSpeedButton_Click(sender, e)

        /// <summary>
        /// Triple Speed 버튼 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void tripleSpeedButton_Click(object sender, RoutedEventArgs e)
        {
            this.storyboard.SetSpeedRatio(this, 3);
        }

        #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(this);
        }

        #endregion
    }
}
728x90
반응형
그리드형(광고전용)
Posted by 사용자 icodebroker

댓글을 달아 주세요