■ DrawingContext 클래스 : AnimationClock 인자를 포함하는 그리기 메소드 사용하기

----------------------------------------------------------------------------------------------------

AnimatedCircle.cs

 

 

using System;

using System.Windows;

using System.Windows.Media;

using System.Windows.Media.Animation;

 

namespace TestProject

{

    /// <summary>

    /// 원 애니메이션

    /// </summary>

    public class CircleAnimation : FrameworkElement

    {

        //////////////////////////////////////////////////////////////////////////////////////////////////// Field

        ////////////////////////////////////////////////////////////////////////////////////////// Private

 

        #region Field

 

        /// <summary>

        /// 실수 애니메이션

        /// </summary>

        private DoubleAnimation doubleAnimation;

 

        /// <summary>

        /// 애니메이션 시계

        /// </summary>

        private AnimationClock animationClock;

 

        #endregion

 

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor

        ////////////////////////////////////////////////////////////////////////////////////////// Public

 

        #region 생성자 - CircleAnimation()

 

        /// <summary>

        /// 생성자

        /// </summary>

        public CircleAnimation()

        {

            this.doubleAnimation = new DoubleAnimation();

 

            this.doubleAnimation.From           = 0;

            this.doubleAnimation.To             = 100;

            this.doubleAnimation.Duration       = new Duration(TimeSpan.FromSeconds(1));

            this.doubleAnimation.AutoReverse    = true;

            this.doubleAnimation.RepeatBehavior = RepeatBehavior.Forever;

 

            this.animationClock = doubleAnimation.CreateClock();

 

        }

 

        #endregion

 

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method

        ////////////////////////////////////////////////////////////////////////////////////////// Protected

 

        #region 렌더링시 처리하기 - OnRender(drawingContext)

 

        /// <summary>

        /// 렌더링시 처리하기

        /// </summary>

        /// <param name="drawingContext">드로잉 컨텍스트</param>

        protected override void OnRender(DrawingContext drawingContext)

        {

            drawingContext.DrawEllipse

            (

                Brushes.Blue,

                new Pen(Brushes.Red, 3),

                new Point(RenderSize.Width / 2, RenderSize.Height / 2),

                null,

                0,

                this.animationClock,

                0,

                this.animationClock

            );

        }

 

        #endregion

    }

}

 

 

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"

    xmlns:local="clr-namespace:TestProject"

    Width="600"

    Height="450"

    Title="DrawingContext 클래스 : AnimationClock 인자를 포함하는 그리기 메소드 사용하기">

    <local:CircleAnimation

        HorizontalAlignment="Center"

        VerticalAlignment="Center" />

</Window>

 

----------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker

댓글을 달아 주세요