如何在wpf中平稳地转换控件

本文关键字:转换 控件 wpf | 更新日期: 2023-09-27 18:11:14

我使用以下代码在wpf中翻译控件:

TranslateTransform trans = new TranslateTransform();
Studio.RenderTransform = trans;
DoubleAnimation anim1 = new DoubleAnimation(0, final_point-initial_point, TimeSpan.FromSeconds(2));
trans.BeginAnimation(TranslateTransform.XProperty, anim1);

然而,这只是线性平移,它始终具有相同的速度。我希望它开始缓慢,然后加速,最后在到达目的地之前再次减速,就像贝塞尔曲线效应一样。如何做到这一点?

如何在wpf中平稳地转换控件

设置DoubleAnimation的EasingFunction属性,例如设置为CubicEase, EasingMode设置为EaseInOut:

anim1.EasingFunction = new CubicEase { EasingMode = EasingMode.EaseInOut };

您必须使用DoubleAnimationUsingKeyFramesSplineDoubleKeyFrame结合使用,如本文所述:

https://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj819806.aspx