[C#/SILVERLIGHT] PointAnimation 엘리먼트 : 실행시 To 속성 동적 변경하기
■ PointAnimation 엘리먼트를 사용해 실행시 속성을 동적 변경하는 방법을 보여준다. ▶ 예제 코드 (XAML)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
<Canvas Name="canvas" Width="600" Height="500" Background="Gray" MouseLeftButtonDown="canvas_MouseLeftButtonDown"> <Canvas.Resources> <Storyboard x:Name="storyboard"> <PointAnimation x:Name="pointAnimation" Storyboard.TargetName="ellipseGeometry" Storyboard.TargetProperty="Center" Duration="0:0:2" /> </Storyboard> </Canvas.Resources> <Path Fill="Blue"> <Path.Data> <EllipseGeometry x:Name="ellipseGeometry" Center="200 100" RadiusX="15" RadiusY="15" /> </Path.Data> </Path> </Canvas> |
▶ 예제 코드 (C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
using System.Windows; using System.Windows.Input; #region 캔버스 마우스 왼쪽 버튼 DOWN시 처리하기 - canvas_MouseLeftButtonDown(sender, e) /// <summary> /// 캔버스 마우스 왼쪽 버튼 DOWN시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void canvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { double newX = e.GetPosition(this.canvas).X; double newY = e.GetPosition(this.canvas).Y; Point toPoint = new Point(); toPoint.X = newX; toPoint.Y = newY; this.pointAnimation.To = toPoint; this.storyboard.Begin(); } #endregion |