WPF编程,通过Double Animation动态缩放控件的一种方法。

时间:2021-09-24 21:34:14

原文:WPF编程,通过Double Animation动态缩放控件的一种方法。

版权声明:我不生产代码,我只是代码的搬运工。 https://blog.csdn.net/qq_43307934/article/details/87260143

 

 1、控件缩放,可直接调用。需要将控件的名称,缩放的位数,时间等参数传进去。

        /// <summary>
/// 控件绕中心缩放动画
/// </summary>
/// <param name="element">控件名</param>
/// <param name="Sizefrom">开始大小</param>
/// <param name="Sizeto">结束大小</param>
/// <param name="power">过渡强度</param>
/// <param name="time">持续时间,例如3秒: TimeSpan(0,0,3) </param>
public void ScaleEasingAnimationShow(UIElement element, double Sizefrom, double Sizeto, int power, TimeSpan time)
{
ScaleTransform scale = new ScaleTransform(); //旋转
element.RenderTransform = scale;
//定义圆心位置
element.RenderTransformOrigin = new System.Windows.Point(0.5, 0.5);
//定义过渡动画,power为过度的强度
EasingFunctionBase easeFunction = new PowerEase()
{
EasingMode = EasingMode.EaseInOut,
Power = power
}; DoubleAnimation scaleAnimation = new DoubleAnimation()
{
From = Sizefrom, //起始值
To = Sizeto, //结束值
FillBehavior = FillBehavior.HoldEnd,
Duration = time, //动画播放时间
};
scale.BeginAnimation(ScaleTransform.ScaleXProperty, scaleAnimation);
scale.BeginAnimation(ScaleTransform.ScaleYProperty, scaleAnimation);
}