■ Vector3KeyFrameAnimation 클래스의 InsertKeyFrame 메소드/Duration 속성을 사용해 벡터 애니메이션을 설정하는 방법을 보여준다.
▶ 예제 코드 (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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
using System; using System.Numerics; using Microsoft.UI.Composition; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Hosting; using Microsoft.UI.Xaml.Media.Imaging; // ... Image image; // ... BitmapImage bitmapImage = new BitmapImage(new Uri("ms-appx:///Assets/landscape.png")); bitmapImage.DecodePixelWidth = 800; bitmapImage.DecodePixelHeight = 600; image.Source = bitmapImage; Visual imageVisual = ElementCompositionPreview.GetElementVisual(image); Compositor compositor = imageVisual.Compositor; Vector3 centerPointVector3 = new Vector3((float)this.image.Width / 2, (float)this.image.Height / 2, 0f); imageVisual.Scale = new Vector3(1, 1, 1); imageVisual.Opacity = 0f; imageVisual.CenterPoint = centerPointVector3; Vector3KeyFrameAnimation scaleAnimation = compositor.CreateVector3KeyFrameAnimation(); scaleAnimation.InsertKeyFrame(0f, new Vector3(1, 1, 1)); CubicBezierEasingFunction scaleCubicBezierEasingFunction = compositor.CreateCubicBezierEasingFunction ( new Vector2(0.1f, 0.9f), new Vector2(0.2f, 1f ) ); scaleAnimation.InsertKeyFrame(1f, new Vector3(6, 6, 1), scaleCubicBezierEasingFunction); scaleAnimation.Duration = TimeSpan.FromSeconds(2); |