Silverlight のアニメーション タイムライン (DoubleAnimation など) には、EasingFunction と呼ばれるプロパティがあり、2 つの値を補間する関数を指定できます。.NET 4 には入っていますが、これを 3.5 に移植したいと考えています。これを読んだ後、それはかなり実行可能に思えますが、私は奇妙な問題を抱えています.
私は DoubleAnimation を次のように拡張しています:
class EasingDoubleAnimation : DoubleAnimation
{
protected override Freezable CreateInstanceCore()
{
return new EasingDoubleAnimation();
}
protected override double GetCurrentValueCore( double defaultOriginValue, double defaultDestinationValue, AnimationClock animationClock )
{
Debug.WriteLine( animationClock.CurrentProgress.Value );
return base.GetCurrentValueCore( defaultOriginValue, defaultDestinationValue, animationClock );
}
public EasingFunctionBase EasingFunction
{
get { return ( EasingFunctionBase ) GetValue( EasingFunctionProperty ); }
set { SetValue( EasingFunctionProperty, value ); }
}
public static readonly DependencyProperty EasingFunctionProperty =
DependencyProperty.Register( "EasingFunction", typeof( EasingFunctionBase ), typeof( EasingDoubleAnimation ),
new PropertyMetadata( null ) );
}
新しいプロパティを追加する以外に興味深いことは何もしていないことに注意してください。
そして、それをいくつかのコードで使用できます。
Storyboard sb = new Storyboard();
EasingDoubleAnimation ease = new EasingDoubleAnimation();
//ease.EasingFunction = new BackEase();
Storyboard.SetTarget( ease, MyTarget );
Storyboard.SetTargetProperty( ease, new PropertyPath( "(Canvas.Left)" ) );
ease.To = 100;
ease.Duration = TimeSpan.FromSeconds( 3 );
sb.Children.Add( ease );
sb.Begin();
そのコードはアニメーションをうまく実行します。
しかし、EasingFunction を設定する行のコメントを外すと、アニメーションは実行されなくなります。CreateInstanceCore メソッドが呼び出されますが、GetCurrentValue は呼び出されません。変?