첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
------------------------------------------------------------------------------------------------------------------------------------------------------
728x90
728x170

TestProject.zip
다운로드

▶ 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
    }
}

 

728x90

 

▶ 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="800"
    Height="600"
    Title="AnimationClock 클래스 사용하기"
    FontFamily="나눔고딕코딩"
    FontSize="16">
    <local:CircleAnimation
        HorizontalAlignment="Center"
        VerticalAlignment="Center" />
</Window>
728x90
그리드형(광고전용)
Posted by icodebroker
,