첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
------------------------------------------------------------------------------------------------------------------------------------------------------
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="AnimationClock 클래스 : 클럭 컨트롤러 사용하기"
    FontFamily="나눔고딕코딩"
    FontSize="16">
    <Grid Margin="10">
        <StackPanel
            HorizontalAlignment="Center"
            VerticalAlignment="Center">
            <Rectangle Name="rectangle"
                HorizontalAlignment="Left"
                Margin="10"
                Width="100"
                Height="30">
                <Rectangle.Fill>
                    <SolidColorBrush>
                        <SolidColorBrush.Color>
                            <Color A="170" R="51" G="51" B="255" />
                        </SolidColorBrush.Color>
                    </SolidColorBrush>
                </Rectangle.Fill>
            </Rectangle>
            <WrapPanel Margin="0 0 0 10">
                <Button Name="beginButton"
                    Margin="10 10 0 0"
                    Width="100"
                    Height="30"
                    Content="Begin" />
                <Button Name="pauseButton"
                    Margin="10 10 0 0"
                    Width="100"
                    Height="30"
                    Content="Pause" />
                <Button Name="resumeButton"
                    Margin="10 10 0 0"
                    Width="100"
                    Height="30"
                    Content="Resume" />
                <Button Name="skipToFillButton"
                    Margin="10 10 0 0"
                    Width="120"
                    Height="30"
                    Content="Skip to Fill" />
                <Button Name="tripleSpeedButton"
                    Margin="10 10 0 0"
                    Width="120"
                    Height="30"
                    Content="Triple Speed" />
                <Button Name="stopButton"
                    Margin="10 10 0 0"
                    Width="100"
                    Height="30"
                    Content="Stop" />
                <Button Name="removeButton"
                    Margin="10 10 0 0"
                    Width="100"
                    Height="30"
                    Content="Remove" />
            </WrapPanel>
            <StackPanel
                Margin="10"
                Orientation="Horizontal">
                <Label
                    VerticalAlignment="Center"
                    Content="Current Time :" />
                <TextBlock Name="currentTimeTextBlock"
                    VerticalAlignment="Center"
                    Margin="10 0 0 0" />
            </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 AnimationClock animationClock;

        #endregion

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

        #region 생성자 - MainWindow()

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

            DoubleAnimation doubleAnimation = new DoubleAnimation
            (
                100,
                500,
                new Duration(TimeSpan.FromSeconds(60))
            );

            this.animationClock = doubleAnimation.CreateClock();

            this.rectangle.ApplyAnimationClock(Rectangle.WidthProperty, this.animationClock);

            this.animationClock.Controller.Stop();

            this.animationClock.CurrentTimeInvalidated += animationClock_CurrentTimeInvalidated;
            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;
            this.removeButton.Click                    += removeButton_Click;
        }

        #endregion

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

        #region 애니메이션 클럭 현재 시간 무효시 처리하기 - animationClock_CurrentTimeInvalidated(sender, e)

        /// <summary>
        /// 애니메이션 클럭 현재 시간 무효시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void animationClock_CurrentTimeInvalidated(object sender, EventArgs e)
        {
            this.currentTimeTextBlock.Text = this.animationClock.CurrentTime.ToString();
        }

        #endregion
        #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.animationClock.Controller.Begin();
        }

        #endregion
        #region Pause 버튼 클릭시 처리하기 - pauseButton_Clicked(sender, e)

        /// <summary>
        /// Pause 버튼 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void pauseButton_Click(object sender, RoutedEventArgs e)
        {
            this.animationClock.Controller.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.animationClock.Controller.Resume();
        }

        #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.animationClock.Controller.SkipToFill();
        }

        #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.animationClock.Controller.SpeedRatio = 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.animationClock.Controller.Stop();
        }

        #endregion
        #region Remove 버튼 클릭시 처리하기 - removeButton_Click(sender, e)

        /// <summary>
        /// Remove 버튼 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void removeButton_Click(object sender, RoutedEventArgs e)
        {
            this.animationClock.Controller.Remove();
        }

        #endregion
    }
}
728x90
그리드형(광고전용)
Posted by icodebroker
,