■ FrameworkElement 클래스 : OnRender 메소드를 사용해 애니메이션 렌더링 하기

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


TestProject.zip


CircleAnimation.cs

 

 

using System;

using System.Windows;

using System.Windows.Media;

using System.Windows.Media.Animation;

 

namespace TestProject

{

    /// <summary>

    /// 원 애니메이션

    /// </summary>

    public class CircleAnimation : FrameworkElement

    {

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

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

 

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

 

        /// <summary>

        /// 렌더링시 처리하기

        /// </summary>

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

        protected override void OnRender(DrawingContext drawingContext)

        {

            DoubleAnimation doubleAnimation = new DoubleAnimation();

 

            doubleAnimation.From           = 0d;

            doubleAnimation.To             = 100d;

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

            doubleAnimation.AutoReverse    = true;

            doubleAnimation.RepeatBehavior = RepeatBehavior.Forever;

 

            AnimationClock animationClock = doubleAnimation.CreateClock();

 

            drawingContext.DrawEllipse

            (

                Brushes.Blue,

                new Pen(Brushes.Red, 3),

                new Point(125, 125),

                null,

                0,

                animationClock,

                0,

                animationClock

            );

        }

 

        #endregion

    }

}

 

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

Posted by 사용자 icodebroker
TAG

댓글을 달아 주세요