[C#/WPF] DoubleAnimationUsingPath 엘리먼트 : 경로를 따라 버튼 움직이기
■ DoubleAnimationUsingPath 엘리먼트를 사용해 경로를 따라 버튼을 움직이는 방법을 보여준다. ▶ MainWindow.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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
<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="800" Title="DoubleAnimationUsingPath 엘리먼트 : 경로를 따라 버튼 움직이기" FontFamily="나눔고딕코딩" FontSize="16"> <Canvas> <Canvas.Resources> <PathGeometry x:Key="PathGeometryKey" Figures="M 96 192 C 288 0, 384 384, 576 192 S 662 192 576 576 S 384 576 96 192" /> </Canvas.Resources> <Path Stroke="Black" Data="{StaticResource PathGeometryKey}" /> <Button Name="button" Width="60" Height="30" Content="버튼"> <Button.RenderTransform> <RotateTransform x:Name="rotateTransform" /> </Button.RenderTransform> </Button> <Canvas.Triggers> <EventTrigger RoutedEvent="Canvas.Loaded"> <BeginStoryboard> <Storyboard RepeatBehavior="Forever"> <DoubleAnimationUsingPath Storyboard.TargetName="button" Storyboard.TargetProperty="(Canvas.Left)" Duration="0:0:10" PathGeometry="{StaticResource PathGeometryKey}" Source="X" /> <DoubleAnimationUsingPath Storyboard.TargetName="button" Storyboard.TargetProperty="(Canvas.Top)" Duration="0:0:10" PathGeometry="{StaticResource PathGeometryKey}" Source="Y" /> <DoubleAnimationUsingPath Storyboard.TargetName="rotateTransform" Storyboard.TargetProperty="Angle" Duration="0:0:10" PathGeometry="{StaticResource PathGeometryKey}" Source="Angle" /> </Storyboard> </BeginStoryboard> </EventTrigger> </Canvas.Triggers> </Canvas> </Window> |
TestProject.zip