■ EasingFunctionBase 클래스를 사용해 커스텀 Easing 함수를 정의하는 방법을 보여준다.
▶ MainPage.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 |
... <Canvas x:Name="canvas" Background="White"> <Canvas.Resources> <Storyboard x:Name="storyboard"> <DoubleAnimation Storyboard.TargetName="rectangle" Storyboard.TargetProperty="Height" Duration="00:00:03" From="30" To="300"> <DoubleAnimation.EasingFunction> <local:CustomEasingFunction EasingMode="EaseIn" /> </DoubleAnimation.EasingFunction> </DoubleAnimation> </Storyboard> </Canvas.Resources> <Rectangle x:Name="rectangle" Canvas.Left="100" Canvas.Top="100" Width="200" Height="30" Fill="Blue" MouseLeftButtonDown="rectangle_MouseLeftButtonDown" /> </Canvas> ... |
▶ MainPage.xaml.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
using System.Windows.Input; ... #region 사각형 마우스 왼쪽 버튼 DOWN시 처리하기 - rectangle_MouseLeftButtonDown(sender, e) /// <summary> /// 사각형 마우스 왼쪽 버튼 DOWN시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="eMouseEventArgs">이벤트 인자</param> private void rectangle_MouseLeftButtonDown(object sender, MouseEventArgs e) { this.storyboard.Begin(); } #endregion ... |
▶ CustomEasingFunction.cs
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 |
using System; using System.Windows.Media.Animation; /// <summary> /// 커스텀 Easing 함수 /// </summary> public class CustomEasingFunction : EasingFunctionBase { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - CustomEasingFunction() /// <summary> /// 생성자 /// </summary> public CustomEasingFunction() : base() { } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Protected #region 사용자 지정 감속/가속 함수 EaseIn 모드 처리하기 - EaseInCore(normalizedTime) /// <summary> /// 사용자 지정 감속/가속 함수 EaseIn 모드 처리하기 /// </summary> /// <param name="normalizedTime">정규화된 시간</param> /// <returns>변환된 진행률</returns> protected override double EaseInCore(double normalizedTime) { return Math.Pow(normalizedTime, 7); } #endregion } |