첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
유용한 소스 코드가 있으면 icodebroker@naver.com으로 보내주시면 감사합니다.
블로그 자료는 자유롭게 사용하세요.

728x90
반응형

■ DoubleAnimation 클래스 : 사각형 높이 변경하기

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


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="DoubleAnimation 클래스 : 사각형 높이 변경하기"

    FontFamily="나눔고딕코딩"

    FontSize="16">

    <Grid>

        <Rectangle Name="rectangle"

            Width="200"

            Height="200">

            <Rectangle.Fill>

                <LinearGradientBrush

                    StartPoint="0 0"

                    EndPoint="0 1">

                    <GradientStop Offset="0"   Color="Red"    />

                    <GradientStop Offset="0.5" Color="Purple" />

                    <GradientStop Offset="1"   Color="Blue"   />

                </LinearGradientBrush>

            </Rectangle.Fill>

        </Rectangle>

    </Grid>

</Window>

 

 

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

            (

                200d,

                100d,

                new Duration(TimeSpan.FromSeconds(2))

            );

 

            doubleAnimation.RepeatBehavior = RepeatBehavior.Forever;

            doubleAnimation.AutoReverse    = true;        

            doubleAnimation.BeginTime      = TimeSpan.FromSeconds(0.5);      

 

            Storyboard.SetTargetName    (doubleAnimation, this.rectangle.Name);

            Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath(Rectangle.HeightProperty));

 

            this.storyboard.Children.Add(doubleAnimation);

 

            Loaded += Window_Loaded;

        }

 

        #endregion

 

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

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

 

        #region 윈도우 로드시 처리하기 - Window_Loaded(sender, e)

 

        /// <summary>

        /// 윈도우 로드시 처리하기

        /// </summary>

        /// <param name="sender">이벤트 발생자</param>

        /// <param name="e">이벤트 인자</param>

        private void Window_Loaded(object sender, RoutedEventArgs e)

        {

            this.storyboard.Begin(this);

        }

 

        #endregion

    }

}

 

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

728x90
반응형
Posted by 사용자 icodebroker

댓글을 달아 주세요