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

728x90
반응형

■ UIElement 클래스 : BeginAnimation 메소드를 사용해 애니메이션 시작하기

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


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="UIElement 클래스 : BeginAnimation 메소드를 사용해 애니메이션 시작하기"

    FontFamily="나눔고딕코딩"

    FontSize="16">

    <Grid>

        <Button Name="button"

            Width="100"

            Height="30"

            Content="테스트">

            <Button.Background>

                <SolidColorBrush x:Name="solidColorBrush"

                    Color="Blue" />

            </Button.Background>

        </Button>

    </Grid>

</Window>

 

 

MainWindow.xaml.cs

 

 

using System;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Media;

using System.Windows.Media.Animation;

 

namespace TestProject

{

    /// <summary>

    /// 메인 윈도우

    /// </summary>

    public partial class MainWindow : Window

    {

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

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

 

        #region 생성자 - MainWindow()

 

        /// <summary>

        /// 생성자

        /// </summary>

        public MainWindow()

        {

            InitializeComponent();

 

            DoubleAnimation doubleAnimation = new DoubleAnimation();

 

            doubleAnimation.RepeatBehavior = RepeatBehavior.Forever;

            doubleAnimation.AutoReverse    = true;

            doubleAnimation.From           = 100;

            doubleAnimation.To             = 300;

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

            

            this.button.BeginAnimation(Button.WidthProperty, doubleAnimation);

 

            ColorAnimation colorAnimation = new ColorAnimation();

 

            colorAnimation.RepeatBehavior = RepeatBehavior.Forever;

            colorAnimation.AutoReverse    = true;

            colorAnimation.From           = Colors.Blue;

            colorAnimation.To             = Colors.Red;

            colorAnimation.Duration       =  new Duration(TimeSpan.FromMilliseconds(7000));

 

            this.solidColorBrush.BeginAnimation(SolidColorBrush.ColorProperty, colorAnimation);

        }

 

        #endregion

    }

}

 

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

728x90
반응형
Posted by 사용자 icodebroker

댓글을 달아 주세요