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

728x90
반응형

■ Storyboard 클래스 사용하기

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


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="Storyboard 클래스 사용하기"

    FontFamily="나눔고딕코딩"

    FontSize="16">

    <Grid>

        <Button Name="button"

            Width="100"

            Height="30"

            Content="테스트" />

    </Grid>

</Window>

 

 

MainWindow.xaml.cs

 

 

using System;

using System.Windows;

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();

 

            NameScope.SetNameScope(this, new NameScope());

 

            ScaleTransform scaleTransform = new ScaleTransform();

 

            RegisterName("scaleTransform", scaleTransform);

 

            scaleTransform.ScaleX  = 1;

            scaleTransform.ScaleY  = 1;

            scaleTransform.CenterX = 50;

            scaleTransform.CenterY = 15;

 

            DoubleAnimation scaleXDoubleAnimation = new DoubleAnimation();

 

            scaleXDoubleAnimation.Duration     = TimeSpan.FromSeconds(1);

            scaleXDoubleAnimation.FillBehavior = FillBehavior.Stop;

            scaleXDoubleAnimation.AutoReverse  = true;

            scaleXDoubleAnimation.From         = 1;

            scaleXDoubleAnimation.To           = 5;

 

            Storyboard.SetTargetName(scaleXDoubleAnimation, "scaleTransform");

 

            Storyboard.SetTargetProperty(scaleXDoubleAnimation, new PropertyPath(ScaleTransform.ScaleXProperty));

 

            DoubleAnimation scaleYDoubleAnimation = new DoubleAnimation();

 

            scaleYDoubleAnimation.Duration     = TimeSpan.FromSeconds(1);

            scaleYDoubleAnimation.FillBehavior = FillBehavior.Stop;

            scaleYDoubleAnimation.AutoReverse  = true;

            scaleYDoubleAnimation.From         = 1;

            scaleYDoubleAnimation.To           = 5;

 

            Storyboard.SetTargetName(scaleYDoubleAnimation, "scaleTransform");

 

            Storyboard.SetTargetProperty(scaleYDoubleAnimation, new PropertyPath(ScaleTransform.ScaleYProperty));

 

            Storyboard storyboard = new Storyboard();

 

            storyboard.Children.Add(scaleXDoubleAnimation);

            storyboard.Children.Add(scaleYDoubleAnimation);

 

            this.button.RenderTransform = scaleTransform;

 

            this.button.Click += delegate(object sender, RoutedEventArgs e)

            {

                storyboard.Begin(this);

            };

        }

 

        #endregion

    }

}

 

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

728x90
반응형
Posted by 사용자 icodebroker

댓글을 달아 주세요