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

▶ XAML

<Canvas x:Name="canvas" />

 

▶ C#

using System;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

Rectangle rectangle = new Rectangle();

rectangle.Width  = 200d;
rectangle.Height = 200d;

Color color = Color.FromArgb(255, 255, 0, 0);

SolidColorBrush solidColorBrush = new SolidColorBrush();

solidColorBrush.Color = color;

rectangle.Fill = solidColorBrush;

this.canvas.Children.Add(rectangle);


Duration duration = new Duration(TimeSpan.FromSeconds(2));

DoubleAnimation leftDoubleAnimation = new DoubleAnimation();
DoubleAnimation topDoubleAnimation  = new DoubleAnimation();

leftDoubleAnimation.Duration = duration;
topDoubleAnimation.Duration  = duration;


Storyboard storyboard = new Storyboard();

storyboard.Children.Add(leftDoubleAnimation);
storyboard.Children.Add(topDoubleAnimation );

Storyboard.SetTarget(leftDoubleAnimation, rectangle);
Storyboard.SetTarget(topDoubleAnimation , rectangle);

Storyboard.SetTargetProperty(leftDoubleAnimation, new PropertyPath("(Canvas.Left)"));
Storyboard.SetTargetProperty(topDoubleAnimation , new PropertyPath("(Canvas.Top)" ));

leftDoubleAnimation.To = 200d;
topDoubleAnimation.To  = 200d;

this.canvas.Resources.Add("StoryboardKey", storyboard);

storyboard.Begin();

 

728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요