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

2021-06-07 23:05

阅读:535

标签:llb   lang   styles   on()   lease   href   template   completed   搬运   

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

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

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

        /// 
        /// 同时旋转和缩放的动画
        /// 
        /// 
        /// 
        /// 
        /// 
        /// 
        /// 
        /// 
        /// 
        public void ScaleEasingAnimationShow(UIElement element,double Sizefrom,double Sizeto,int anglefrom, int angleto ,TimeSpan time,int Power,EventHandler completed)
        {

            RotateTransform angle = new RotateTransform();  //旋转
            ScaleTransform scale = new ScaleTransform();   //缩放

            TransformGroup group = new TransformGroup();
            group.Children.Add(scale);
            group.Children.Add(angle);

            element.RenderTransform = group;
            //定义圆心位置
            //元素开始的位置是从new Point(0,0)到new Point(1,1),
            //左上角为(0,0)、右下角为(1,1),控件大小范围为(1,0) 1为控件本身大小,0 为控件缩放完,不显示。
            element.RenderTransformOrigin = new System.Windows.Point(0.5, 0.5);   
            //载入动画,淡入淡出等。
            EasingFunctionBase easeFunction = new PowerEase()
            {
                EasingMode = EasingMode.EaseInOut,
                Power = Power
            };
            //缩放动画
            DoubleAnimation scaleAnimation = new DoubleAnimation()
            {
                From = Sizefrom,                                   //起始值
                To = Sizeto,                                     //结束值
                EasingFunction = easeFunction,                    //缓动函数
                Duration = time,  //动画播放时间


            };
            //旋转动画
            DoubleAnimation angleAnimation = new DoubleAnimation()
            {
                From = anglefrom,                                   //起始值
                To = angleto,                                     //结束值
                EasingFunction = easeFunction,              //缓动函数
                FillBehavior = FillBehavior.HoldEnd,
                Duration = time,  //动画播放时间

            };

            angleAnimation.Completed += completed;
            //scaleAnimation.Completed += new EventHandler(scaleAnimation_Completed);
            //  AnimationClock clock = scaleAnimation.CreateClock();
            scale.BeginAnimation(ScaleTransform.ScaleXProperty, scaleAnimation);
            scale.BeginAnimation(ScaleTransform.ScaleYProperty, scaleAnimation);
            angle.BeginAnimation(RotateTransform.AngleProperty, angleAnimation);
            
        }

?

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

标签:llb   lang   styles   on()   lease   href   template   completed   搬运   

原文地址:https://www.cnblogs.com/lonelyxmas/p/10729330.html


评论


亲,登录后才可以留言!