Silverlight 动画类的使用

    技术2022-07-04  122

    AnimationSL 为我的一个动画类,见前一篇博文。

    首先定义几个动画,这里使用静态类,看情况自己定,这样就可以实现,动画一次定义,多次使用,不同的对象上都可以复用这个定义好的动画。

     

            /// <summary>        /// 水平翻转360度        /// </summary>        public static AnimationSL InvertHorizontal        {            get            {                AnimationSL _Animation = new AnimationSL();                _Animation.DropShadowEffect.IsEnabled = true;                _Animation.RenderTransformOrigin.AddCenter(0.5, 0.5, 0);                _Animation.CompositeTransform.AddScaleX(-1, 0);                _Animation.CompositeTransform.AddScaleX(1, 500);                return _Animation;            }        }

            /// <summary>        /// 垂直翻转360度        /// </summary>        public static AnimationSL InvertVertical        {            get            {                AnimationSL _Animation = new AnimationSL();                _Animation.RenderTransformOrigin.AddCenter(0.5, 0.5, 0);                _Animation.CompositeTransform.AddScaleY(-1, 0);                _Animation.CompositeTransform.AddScaleY(1, 500);                _Animation.DropShadowEffect.IsEnabled = false;                return _Animation;            }        }

            /// <summary>        /// 震动弹出        /// </summary>        public static AnimationSL Pop_Shock        {            get            {                AnimationSL _Animation = new AnimationSL();                _Animation.RenderTransformOrigin.AddCenter(0.5, 0.5, 0);                _Animation.ScaleTransform.AddScaleX(0, 0);                _Animation.ScaleTransform.AddScaleY(0, 0);                _Animation.ScaleTransform.AddScaleX(3, 100);                _Animation.ScaleTransform.AddScaleY(3, 100);                _Animation.ScaleTransform.AddScaleX(1, 300);                _Animation.ScaleTransform.AddScaleY(1, 300);                return _Animation;            }        }

     

    下面定义一个动画的扩展属性,方便调用动画

            #region 扩展动画属性        /// <summary>        /// FrameworkElement扩展动画属性        /// </summary>        public static DependencyProperty AnimationSL =            DependencyProperty.Register("Animation", typeof(List<AnimationSL>), typeof(FrameworkElement), new PropertyMetadata(null));        /// <summary>        /// FrameworkElement扩展动画方法        /// </summary>        /// <param name="UI">FrameworkElement对象</param>        /// <returns></returns>        public static List<AnimationSL> Animation(this FrameworkElement UI)        {            List<AnimationSL> _Animation = new List<AnimationSL>();            if (UI.GetValue(AnimationSL) == null)            {                UI.SetValue(AnimationSL, _Animation);            }            _Animation = UI.GetValue(AnimationSL) as List<AnimationSL>;            foreach (AnimationSL animation in _Animation)            {                animation.UI = UI;            }

                return _Animation;        }        #endregion

     

    下面是具体的使用方法了:

    例如像对一个ListBox执行一个反转的动画:定义如下,就一句话。

            ListBox1.Animation().Add(AnimationEffect.InvertHorizontal);

    需要的时候执行就可以了:        ListBox1.Animation()[0].Begin();

     

    使用起来简单的很,动画类中还定义了一些事件,方便制作各种效果和开发使用。


    最新回复(0)