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

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="FrameworkElement 클래스 : RegisterName 메소드를 사용해 동적 명칭 등록하기"
    FontFamily="나눔고딕코딩"
    FontSize="16">
    <Grid>
        <Button Name="button"
            Width="100"
            Height="30"
            Content="테스트" />
    </Grid>
</Window>

 

728x90

 

▶ 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

댓글을 달아 주세요