private void sizeAnim_Completed(object sender, EventArgs e)
            {
                _control.Margin = _originalMargin;
                _control.Height = _height;
                _control.ApplyAnimationClock(FrameworkElement.HeightProperty, null);
                _control.ApplyAnimationClock(FrameworkElement.MarginProperty, null);

                DoubleAnimation opacityAnim = new DoubleAnimation(1, AnimationDuration, FillBehavior.Stop);

                opacityAnim.EasingFunction = EasingFunction;
                opacityAnim.Completed     += opacityAnim_Completed;

                _control.BeginAnimation(FrameworkElement.OpacityProperty, opacityAnim);
            }
            private void scaleInAnim_Completed(object sender, EventArgs e)
            {
                _switchIn.ApplyAnimationClock(FrameworkElement.OpacityProperty, null);

                ScaleTransform scaleTransform = (ScaleTransform)GetRenderTransform(_switchIn, typeof(ScaleTransform));

                scaleTransform.ApplyAnimationClock(ScaleTransform.ScaleXProperty, null);
                scaleTransform.ApplyAnimationClock(ScaleTransform.ScaleYProperty, null);

                scaleTransform.ScaleX = scaleTransform.ScaleY = 1;

                _switchIn.Opacity = 1;

                AnimationCompletedEvent(new EventArgs());
            }
Example #3
0
        public void AnimationExpressionFillBehaviorStopTest()
        {
            DoubleAnimation animation = new DoubleAnimation {
                From = 10, To = 20, FillBehavior = FillBehavior.Stop
            };

            TestRootClock rootClock = new TestRootClock();

            rootClock.Tick(TimeSpan.FromSeconds(1));

            FrameworkElement element = new FrameworkElement();

            Assert.AreEqual(Double.NaN, element.Width);

            AnimationTimelineClock animationClock = (AnimationTimelineClock)animation.CreateClock();

            element.ApplyAnimationClock(FrameworkElement.WidthProperty, animationClock);
            animationClock.Begin(rootClock);

            rootClock.Tick(TimeSpan.FromSeconds(1));
            Assert.AreEqual(10, element.Width);

            rootClock.Tick(TimeSpan.FromSeconds(2));
            Assert.AreEqual(Double.NaN, element.Width);
        }
Example #4
0
        private void ApplyAnimationClockTest(DoubleAnimation animation)
        {
            FrameworkElement element = new FrameworkElement();

            TestRootClock rootClock = new TestRootClock();

            rootClock.Tick(TimeSpan.FromSeconds(0));

            AnimationTimelineClock clock = (AnimationTimelineClock)animation.CreateClock();

            clock.Begin(rootClock);

            element.Width = 10;
            Assert.AreEqual(10, element.Width);

            element.ApplyAnimationClock(FrameworkElement.WidthProperty, clock);
            Assert.AreEqual(10, element.Width);

            rootClock.Tick(TimeSpan.FromSeconds(0.5));
            Assert.AreEqual(15, element.Width);

            rootClock.Tick(TimeSpan.FromSeconds(1));
            Assert.AreEqual(20, element.Width);

            clock.Stop();

            element.Width = 30;
            Assert.AreEqual(30, element.Width);
        }
        public static void Move(FrameworkElement target, Thickness from, Thickness to, double durationMilliseconds, EasingMode easingMode, Action callBack)
        {
            EasingFunctionBase easeFunction = new PowerEase()
            {
                EasingMode = easingMode,
                Power      = EasingPower
            };
            ThicknessAnimation animation = new ThicknessAnimation()
            {
                From           = from,                                           //起始值
                To             = to,                                             //结束值
                EasingFunction = easeFunction,                                   //缓动函数
                Duration       = TimeSpan.FromMilliseconds(durationMilliseconds) //动画播放时间
            };

            if (callBack != null)
            {
                animation.Completed += (sender, e) =>
                {
                    callBack();
                };
            }

            AnimationClock clock = animation.CreateClock();

            target.ApplyAnimationClock(FrameworkElement.MarginProperty, clock);
        }
Example #6
0
        public static void FadeOut(this FrameworkElement element, FrameworkElement crossFade = null)
        {
            if (element.Opacity != 0)
            {
                DoubleAnimation fadeOutAnim = new DoubleAnimation(0, AnimationDuration);

                fadeOutAnim.Completed += (sender, e) =>
                {
                    if (element != null)
                    {
                        element.Visibility = Visibility.Hidden;
                        element.Opacity    = 0;
                        element.ApplyAnimationClock(FrameworkElement.OpacityProperty, null);
                    }

                    if (crossFade != null)
                    {
                        crossFade.FadeIn();
                    }
                };

                element.BeginAnimation(FrameworkElement.OpacityProperty, fadeOutAnim);
            }
            else if (crossFade != null)
            {
                crossFade.FadeIn();
            }
        }
Example #7
0
        public static void FadeOut(this FrameworkElement element, Duration fadeDuration, FrameworkElement crossFade = null, bool delayCrossFade = true)
        {
            DoubleAnimation fadeOutAnim = new DoubleAnimation(1, 0, fadeDuration);

            fadeOutAnim.Completed += (sender, e) =>
            {
                if (element != null)
                {
                    element.Opacity = 0;
                    element.ApplyAnimationClock(FrameworkElement.OpacityProperty, null);
                }

                if (delayCrossFade && crossFade != null)
                {
                    crossFade.FadeIn(fadeDuration);
                }
            };

            element.BeginAnimation(FrameworkElement.OpacityProperty, fadeOutAnim);

            if (!delayCrossFade && crossFade != null)
            {
                crossFade.FadeIn(fadeDuration);
            }
        }
            private void anim_Completed(object sender, EventArgs e)
            {
                _grid.ApplyAnimationClock(FrameworkElement.OpacityProperty, null);
                //_grid.ApplyAnimationClock(FrameworkElement.MarginProperty, null);

                GetRenderTransform(_grid, typeof(TranslateTransform)).ApplyAnimationClock(TranslateTransform.XProperty, null);

                AnimationCompletedEvent(e);
            }
Example #9
0
        private static void SlideLeft(FrameworkElement slideElement, Image image)
        {
            QuarticEase Ease = new QuarticEase();

            Ease.EasingMode = EasingMode.EaseIn;

            ThicknessAnimation leftAnim1 = new ThicknessAnimation(new Thickness(0), new Thickness(60, 0, -60, 0), AnimationDuration, FillBehavior.Stop);

            leftAnim1.EasingFunction = Ease;

            leftAnim1.Completed += (sender, e) =>
            {
                image.Visibility = Visibility.Hidden;
                image.ApplyAnimationClock(FrameworkElement.OpacityProperty, null);
                image.ApplyAnimationClock(FrameworkElement.MarginProperty, null);

                QuarticEase Ease2 = new QuarticEase();
                Ease2.EasingMode = EasingMode.EaseOut;

                slideElement.Visibility = Visibility.Visible;

                ThicknessAnimation leftAnim2 = new ThicknessAnimation(new Thickness(-60, 0, 60, 0), new Thickness(0), AnimationDuration, FillBehavior.Stop);
                leftAnim2.EasingFunction = Ease2;
                leftAnim2.Completed     += (_sender, _e) =>
                {
                    slideElement.ApplyAnimationClock(FrameworkElement.OpacityProperty, null);
                    slideElement.ApplyAnimationClock(FrameworkElement.MarginProperty, null);
                };

                DoubleAnimation opac2 = new DoubleAnimation(0, 1, AnimationDuration, FillBehavior.Stop);
                opac2.EasingFunction = Ease2;

                slideElement.BeginAnimation(FrameworkElement.OpacityProperty, opac2);
                slideElement.BeginAnimation(FrameworkElement.MarginProperty, leftAnim2);
            };

            DoubleAnimation opac = new DoubleAnimation(1, 0, AnimationDuration, FillBehavior.Stop);

            opac.EasingFunction = Ease;

            image.BeginAnimation(FrameworkElement.OpacityProperty, opac);
            image.BeginAnimation(FrameworkElement.MarginProperty, leftAnim1);
        }
Example #10
0
            public static void Stop(FrameworkElement element)
            {
                SortAnimation animation = GetSortAnimation(element);

                if (animation != null)
                {
                    animation._canceled = true;
                }

                element.ApplyAnimationClock(FrameworkElement.MarginProperty, null);
            }
Example #11
0
            private void opacityAnim_Completed(object sender, EventArgs e)
            {
                _control.Opacity = 0;
                _control.ApplyAnimationClock(FrameworkElement.OpacityProperty, null);

                DoubleAnimation sizeAnim = new DoubleAnimation(_control.RenderSize.Height, 0, AnimationDuration, FillBehavior.Stop);

                sizeAnim.EasingFunction = EasingFunction;
                sizeAnim.Completed     += sizeAnim_Completed;

                Thickness margin   = _control.Margin;
                Thickness toMargin = margin;

                toMargin.Top    = 0;
                toMargin.Bottom = 0;

                ThicknessAnimation marginAnim = new ThicknessAnimation(margin, toMargin, AnimationDuration, FillBehavior.Stop);

                marginAnim.EasingFunction = EasingFunction;

                _control.BeginAnimation(FrameworkElement.MarginProperty, marginAnim);
                _control.BeginAnimation(FrameworkElement.HeightProperty, sizeAnim);
            }
Example #12
0
            private void scaleOutAnim_Completed(object sender, EventArgs e)
            {
                QuarticEase Ease = new QuarticEase();

                Ease.EasingMode = EasingMode.EaseOut;

                _switchOut.Visibility = Visibility.Collapsed;
                _switchOut.ApplyAnimationClock(FrameworkElement.OpacityProperty, null);

                ScaleTransform scaleOut = (ScaleTransform)GetRenderTransform(_switchOut, typeof(ScaleTransform));

                scaleOut.ApplyAnimationClock(ScaleTransform.ScaleXProperty, null);
                scaleOut.ApplyAnimationClock(ScaleTransform.ScaleYProperty, null);

                ScaleTransform scaleIn = (ScaleTransform)GetRenderTransform(_switchIn, typeof(ScaleTransform));

                scaleIn.CenterX = centerX;
                scaleIn.CenterY = centerY;
                scaleIn.ScaleX  = scaleIn.ScaleY = 0.9;

                DoubleAnimation scaleInAnim = new DoubleAnimation(1, AnimationDuration, FillBehavior.Stop);

                scaleInAnim.Completed     += scaleInAnim_Completed;
                scaleInAnim.EasingFunction = Ease;

                _switchIn.Visibility = Visibility.Visible;

                DoubleAnimation opacityInAnim = new DoubleAnimation(0, 1, AnimationDuration, FillBehavior.Stop);

                // To do, or not to do
                opacityInAnim.EasingFunction = Ease;

                scaleIn.BeginAnimation(ScaleTransform.ScaleXProperty, scaleInAnim);
                scaleIn.BeginAnimation(ScaleTransform.ScaleYProperty, scaleInAnim);

                _switchIn.BeginAnimation(FrameworkElement.OpacityProperty, opacityInAnim);
            }
Example #13
0
        public static void FadeIn(this FrameworkElement element, Duration fadeDuration)
        {
            DoubleAnimation fadeInAnim = new DoubleAnimation(0, 1, fadeDuration);

            fadeInAnim.Completed += (sender, e) =>
            {
                if (element != null)
                {
                    element.Opacity = 1;
                    element.ApplyAnimationClock(FrameworkElement.OpacityProperty, null);
                }
            };

            element.BeginAnimation(FrameworkElement.OpacityProperty, fadeInAnim);
        }
Example #14
0
            private void anim_Completed(object sender, EventArgs e)
            {
                if (_direction == FadeDirection.In)
                {
                    _element.Opacity = _opaqueOpacity;
                }
                else
                {
                    _element.Opacity = _transparentOpacity;

                    if (_hideoncomplete)
                    {
                        _element.Visibility = Visibility.Hidden;
                    }
                }

                _element.ApplyAnimationClock(FrameworkElement.OpacityProperty, null);

                AnimationCompletedEvent(e);
            }
Example #15
0
 private void Animate(FrameworkElement element, Thickness newMargin)
 {
     if (Settings.AnimationsEnabled)
     {
         ThicknessAnimation anim = new ThicknessAnimation(newMargin, new Duration(TimeSpan.FromMilliseconds(200)));
         anim.EasingFunction = EasingFunction;
         anim.Completed     += (sender, e) =>
         {
             if (!_canceled && GetSortAnimation(element) == this)
             {
                 element.Margin = newMargin;
                 element.ApplyAnimationClock(FrameworkElement.MarginProperty, null);
             }
         };
         element.BeginAnimation(FrameworkElement.MarginProperty, anim);
     }
     else
     {
         element.Margin = newMargin;
     }
 }