[C#/WPF] DoubleAnimationUsingKeyFrames 엘리먼트 : 뉴턴의 요람(Newton's Cradle) 만들기
C#/WPF 2015. 10. 13. 07:22728x90
728x170
■ DoubleAnimationUsingKeyFrames 엘리먼트을 사용해 뉴턴의 요람(Newton's Cradle) 애니메이션을 만드는 방법을 보여준다.
▶ 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="DoubleAnimationUsingKeyFrames 엘리먼트 : 뉴턴의 요람(Newton's Cradle) 만들기"
FontFamily="나눔고딕코딩"
FontSize="16">
<Canvas>
<Canvas.Resources>
<Style TargetType="{x:Type Path}">
<Setter Property="Fill" Value="Silver" />
<Setter Property="Stroke" Value="Black" />
<Setter Property="StrokeThickness" Value="3" />
<Setter
Property="Data"
Value="M 0 0 V 300 A 25 25 0 1 1 0 350 A 25 25 0 1 1 0 300" />
</Style>
</Canvas.Resources>
<Path>
<Path.RenderTransform>
<TransformGroup>
<RotateTransform x:Name="rotateTransform1"
Angle="30" />
<TranslateTransform X="200" />
</TransformGroup>
</Path.RenderTransform>
</Path>
<Path>
<Path.RenderTransform>
<TransformGroup>
<RotateTransform x:Name="rotateTransform2"
Angle="30" />
<TranslateTransform X="252" />
</TransformGroup>
</Path.RenderTransform>
</Path>
<Path>
<Path.RenderTransform>
<TransformGroup>
<RotateTransform x:Name="rotateTransform3"
Angle="30" />
<TranslateTransform X="304" />
</TransformGroup>
</Path.RenderTransform>
</Path>
<Path>
<Path.RenderTransform>
<TransformGroup>
<RotateTransform x:Name="rotateTransform4" />
<TranslateTransform X="356" />
</TransformGroup>
</Path.RenderTransform>
</Path>
<Path>
<Path.RenderTransform>
<TransformGroup>
<RotateTransform x:Name="rotateTransform5" />
<TranslateTransform X="408" />
</TransformGroup>
</Path.RenderTransform>
</Path>
<Canvas.Triggers>
<EventTrigger
RoutedEvent="Page.Loaded">
<BeginStoryboard>
<Storyboard
TargetProperty="Angle"
RepeatBehavior="Forever">
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="rotateTransform1">
<DiscreteDoubleKeyFrame KeyTime="0:0:0" Value="30" />
<SplineDoubleKeyFrame KeyTime="0:0:1" Value="0" KeySpline="0.25 0 0.6 0.2" />
<DiscreteDoubleKeyFrame KeyTime="0:0:3" Value="0" />
<SplineDoubleKeyFrame KeyTime="0:0:4" Value="30" KeySpline="0.75 1 0.4 0.8" />
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="rotateTransform2">
<DiscreteDoubleKeyFrame KeyTime="0:0:0" Value="30" />
<SplineDoubleKeyFrame KeyTime="0:0:1" Value="0" KeySpline="0.25 0 0.6 0.2" />
<DiscreteDoubleKeyFrame KeyTime="0:0:3" Value="0" />
<SplineDoubleKeyFrame KeyTime="0:0:4" Value="30" KeySpline="0.75 1 0.4 0.8" />
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="rotateTransform3">
<DiscreteDoubleKeyFrame KeyTime="0:0:0" Value="30" />
<SplineDoubleKeyFrame KeyTime="0:0:1" Value="0" KeySpline="0.25 0 0.6 0.2" />
<SplineDoubleKeyFrame KeyTime="0:0:2" Value="-30" KeySpline="0.75 1 0.4 0.8" />
<SplineDoubleKeyFrame KeyTime="0:0:3" Value="0" KeySpline="0.25 0 0.6 0.2" />
<SplineDoubleKeyFrame KeyTime="0:0:4" Value="30" KeySpline="0.75 1 0.4 0.8" />
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="rotateTransform4">
<DiscreteDoubleKeyFrame KeyTime="0:0:0" Value="0" />
<DiscreteDoubleKeyFrame KeyTime="0:0:1" Value="0" />
<SplineDoubleKeyFrame KeyTime="0:0:2" Value="-30" KeySpline="0.75 1 0.4 0.8" />
<SplineDoubleKeyFrame KeyTime="0:0:3" Value="0" KeySpline="0.25 0 0.6 0.2" />
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="rotateTransform5">
<DiscreteDoubleKeyFrame KeyTime="0:0:0" Value="0" />
<DiscreteDoubleKeyFrame KeyTime="0:0:1" Value="0" />
<SplineDoubleKeyFrame KeyTime="0:0:2" Value="-30" KeySpline="0.75 1 0.4 0.8" />
<SplineDoubleKeyFrame KeyTime="0:0:3" Value="0" KeySpline="0.25 0 0.6 0.2" />
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Canvas.Triggers>
</Canvas>
</Window>
728x90
그리드형(광고전용)
'C# > WPF' 카테고리의 다른 글
[C#/WPF] DoubleAnimationUsingPath 엘리먼트 : 문자열 깜박이기 (0) | 2015.10.14 |
---|---|
[C#/WPF] DoubleAnimationUsingPath 엘리먼트 : 경로를 따라 버튼 움직이기 (0) | 2015.10.14 |
[C#/WPF] WinForm Form의 소유자를 WPF Window로 설정하기 (0) | 2015.10.14 |
[C#/WPF] DoubleAnimationUsingPath 엘리먼트 : 경로를 따라 버튼 움직이기 (0) | 2015.10.13 |
[C#/WPF] PointAnimationUsingPath 엘리먼트 : 경로를 따라 공 움직이기 (0) | 2015.10.13 |
[C#/WPF] DoubleAnimationUsingKeyFrames 엘리먼트 : 공 떨어뜨리기 (0) | 2015.10.11 |
[C#/WPF] DependencyPropertyDescriptor 클래스 : 의존 속성 변경시 이벤트 핸들러 추가하기 (0) | 2015.10.10 |
[C#/WPF] DynamicResource 엘리먼트 : 리소스 사용하기 (0) | 2015.10.10 |
[C#/WPF] ColorAnimationUsingKeyFrames 엘리먼트 사용하기 (0) | 2015.10.08 |
[C#/WPF] StringAnimationUsingKeyFrames 엘리먼트 : 문자열 교대로 표시하기 (0) | 2015.10.08 |