Пример #1
0
        public static void StopDoubleAnimation(this Animatable obj, DependencyProperty property)
        {
            var anim = new DoubleAnimation(0, 0, new Duration());

            anim.BeginTime = null;
            obj.BeginAnimation(property, anim);
        }
Пример #2
0
        public static void AnimateEaseIn(this Animatable obj, DependencyProperty property, Thickness fromValue, Thickness toValue, TimeSpan duration)
        {
            var anim = new ThicknessAnimation(fromValue, toValue, new Duration(duration));

            anim.AccelerationRatio = 1;
            obj.BeginAnimation(property, anim);
        }
Пример #3
0
        public static void AnimateEaseOut(this Animatable obj, DependencyProperty property, double fromValue, double toValue, TimeSpan duration)
        {
            var anim = new DoubleAnimation(fromValue, toValue, new Duration(duration));

            anim.DecelerationRatio = 1;
            obj.BeginAnimation(property, anim);
        }
Пример #4
0
        /// <summary>
        /// Double 애니메이션을 실행합니다.
        /// </summary>
        /// <param name="animatable"></param>
        /// <param name="property"></param>
        /// <param name="toValue"></param>
        /// <param name="duration"></param>
        /// <param name="easing"></param>
        /// <param name="completedEvent"></param>
        public static void BeginDoubleAnimation(
            this Animatable animatable,
            DependencyProperty property,
            double toValue,
            double duration             = 400,
            IEasingFunction easing      = null,
            EventHandler completedEvent = null)
        {
            double fromValue = (double)animatable.GetValue(property);

            var animation = new DoubleAnimation()
            {
                To             = toValue,
                Duration       = TimeSpan.FromMilliseconds(duration),
                EasingFunction = easing,
                FillBehavior   = FillBehavior.HoldEnd
            };

            if (completedEvent != null)
            {
                animation.Completed += completedEvent;
            }

            animatable.BeginAnimation(property, animation);
        }
        public static void Animate(this Animatable self, DependencyProperty property, double from, double to, int durationMs)
        {
            DoubleAnimation anim = new DoubleAnimation(from, to, new Duration(TimeSpan.FromMilliseconds(durationMs)));

            anim.EasingFunction = new QuadraticEase();
            self.BeginAnimation(property, anim);
        }
Пример #6
0
        /*private void face_MouseLeave(object sender, MouseEventArgs e)
         * {
         *              var el = (ModelUIElement3D) sender;
         *              var model = el.Model as GeometryModel3D;
         *              var mg = model.Material as MaterialGroup;
         *              var dm = mg.Children[0] as DiffuseMaterial;
         *              AnimateOpacity(dm.Brush, 0.8, 200);
         * }
         *
         * private void face_MouseEnter(object sender, MouseEventArgs e)
         * {
         *  var el = (ModelUIElement3D) sender;
         *      var model = el.Model as GeometryModel3D;
         *      var mg=model.Material as MaterialGroup;
         *      var dm=mg.Children[0] as DiffuseMaterial;
         *      AnimateOpacity(dm.Brush, 1.0, 200);
         * }*/


        private void AnimateOpacity(Animatable obj, double toOpacity, double animationTime)
        {
            var a = new DoubleAnimation(toOpacity,
                                        new Duration(TimeSpan.FromMilliseconds(animationTime)))
            {
                AccelerationRatio = 0.3, DecelerationRatio = 0.5
            };

            a.Completed += new EventHandler(a_Completed);
            obj.BeginAnimation(UIElement.OpacityProperty, a);
        }
Пример #7
0
        /// <summary>
        /// The animate opacity.
        /// </summary>
        /// <param name="obj">
        /// The obj.
        /// </param>
        /// <param name="toOpacity">
        /// The to opacity.
        /// </param>
        /// <param name="animationTime">
        /// The animation time.
        /// </param>
        private void AnimateOpacity(Animatable obj, double toOpacity, double animationTime)
        {
            var animation = new DoubleAnimation(toOpacity, new Duration(TimeSpan.FromMilliseconds(animationTime)))
            {
                AccelerationRatio = 0.3,
                DecelerationRatio = 0.5
            };

            animation.Completed += this.AnimationCompleted;
            obj.BeginAnimation(UIElement.OpacityProperty, animation);
        }
Пример #8
0
        public void BeginAnimation(DependencyProperty dependencyProperty)
        {
            if ((_IsDeploying) && (this.GetPropertyValue(dependencyProperty) == _DeployedValue))
            {
                this.SetToStowedValue(dependencyProperty);
            }
            else if ((!_IsDeploying) && (this.GetPropertyValue(dependencyProperty) == _StowedValue))
            {
                this.SetToDeployedValue(dependencyProperty);
            }

            _Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(delegate()
            {
                double toValue            = _IsDeploying ? _DeployedValue : _StowedValue;
                double currentValue       = (double)_AnimationedObject.GetValue(dependencyProperty);
                double timeRemaining      = (_AnimationTimePerValue * Math.Abs(toValue - currentValue));
                Duration duration         = new Duration(TimeSpan.FromMilliseconds(timeRemaining));
                DoubleAnimation animation = new DoubleAnimation(currentValue, toValue, duration);
                _AnimationedObject.BeginAnimation(dependencyProperty, animation);
            }));
        }
Пример #9
0
        public static void BeginColorAnimation(Animatable obj, DependencyProperty property, Color?from, Color?to, TimeSpan?duration = null, TimeSpan?beginTime = null, AnimationEase?ease = null, Action callback = null)
        {
            var anima = new ColorAnimation()
            {
                From           = from,
                To             = to,
                Duration       = duration ?? GlobalSettings.Setting.AnimationDuration,
                BeginTime      = beginTime ?? TimeSpan.Zero,
                EasingFunction = CreateEasingFunction(ease),
            };

            if (callback != null)
            {
                anima.Completed += delegate
                {
                    callback?.Invoke();
                };
            }

            obj.BeginAnimation(property, anima);
        }
Пример #10
0
        /// <summary>
        ///     Animate a given <see cref="Animatable" /> asynchronous (awaitable)
        /// </summary>
        /// <param name="element">The Element to animate (Button, Label, Window, ..)</param>
        /// <param name="dp">The Property to animate (OpacityProperty, ..)</param>
        /// <param name="from">The beginning value of the animation</param>
        /// <param name="to">The value once the animation finishes</param>
        /// <param name="duration">The duration of this animation</param>
        /// <param name="beginTime">The delay before beginning the animation</param>
        public static async Task AnimateAsync(this Animatable element, DependencyProperty dp, double from, double to,
                                              int duration, int beginTime = 0)
        {
            TaskCompletionSource <bool> tcs = new TaskCompletionSource <bool>();

            try {
                await element.Dispatcher.BeginInvoke(new Action(() => {
                    var animation = new DoubleAnimation(from, to, TimeSpan.FromMilliseconds(duration))
                    {
                        BeginTime = TimeSpan.FromMilliseconds(beginTime)
                    };
                    animation.Completed += delegate { tcs.SetResult(true); };
                    element.BeginAnimation(dp, animation);
                }));
            } catch {
                //Task was canceled
                return;
            }

            await tcs.Task;
        }
Пример #11
0
 static void Animate(Animatable element, DependencyProperty property, double to)
 {
     element.BeginAnimation(property, new DoubleAnimation(to, new Duration(animationTime), FillBehavior.HoldEnd),
                            HandoffBehavior.SnapshotAndReplace);
 }
Пример #12
0
 /// <summary>
 /// 진행중인 애니메이션을 중단합니다.
 /// </summary>
 /// <param name="animatable"></param>
 /// <param name="property"></param>
 public static void StopAnimation(this Animatable animatable, DependencyProperty property)
 {
     animatable.SetValue(property, animatable.GetValue(property));
     animatable.BeginAnimation(property, null);
 }