Example #1
0
        private void ToggleView(Control ui, bool isShow)
        {
            DoubleAnimation animation;

            if (isShow)
            {
                if (ui.ActualWidth != 0)
                {
                    return;
                }
                animation = CustomAnimation.GetEnteringScreenAnimation(0,
                                                                       ui is Label ? _widthOfToLabel : _widthOfTimeChooser, false);
                ui.BeginAnimation(WidthProperty, animation);
            }
            else
            {
                if (ui.ActualWidth == 0)
                {
                    return;
                }
                animation =
                    CustomAnimation.GetLeavingScreenAnimation(ui is Label ? _widthOfToLabel : _widthOfTimeChooser, 0,
                                                              false);
                ui.BeginAnimation(WidthProperty, animation);
            }
        }
Example #2
0
        /// <summary>
        /// 界面淡出
        /// </summary>
        /// <param name="window"></param>
        /// <param name="second">淡出时间</param>
        public static void Fade_Out_Window(Control window, double second)
        {
            DoubleAnimation da = new DoubleAnimation
            {
                From     = 1,                           //起始值
                To       = 0,                           //结束值
                Duration = TimeSpan.FromSeconds(second) //动画持续时间
            };

            window.BeginAnimation(UIElement.OpacityProperty, da);//开始动画
        }
Example #3
0
        /// <summary>
        /// 界面淡入【一秒】
        /// </summary>
        /// <param name="control"></param>
        public static void Fade_Int_Window(Control control)
        {
            control.Opacity = 0;
            DoubleAnimation da = new DoubleAnimation
            {
                From     = 0,                      //起始值
                To       = 1,                      //结束值
                Duration = TimeSpan.FromSeconds(1) //动画持续时间
            };

            control.BeginAnimation(UIElement.OpacityProperty, da);//开始动画
        }
Example #4
0
 // Plays the show animation for the given controls.
 private void DoFadeInAnimation(Control control)
 {
     // Fade in Animation.
     if (control.Opacity == 0)
     {
         DoubleAnimation da = new DoubleAnimation();
         da.From      = 0;
         da.To        = 1;
         da.Duration  = new Duration(TimeSpan.FromSeconds(0.25));
         da.BeginTime = TimeSpan.FromMilliseconds(100);
         control.BeginAnimation(OpacityProperty, da);
     }
 }
        private void StartDisappearAnimation(Control lControl)
        {
            DoubleAnimation lAnimation = new DoubleAnimation(0.0, new Duration(TimeSpan.FromMilliseconds(1000)));

            lAnimation.BeginTime  = TimeSpan.FromSeconds(4);
            lAnimation.Completed += (sender, args) => {
                if (lControl.Opacity < 0.01)
                {
                    ItemsControl.Items.Remove(lControl);
                }
            };
            lControl.BeginAnimation(OpacityProperty, lAnimation);
        }
        public void Animate(IAnimationContext context, Control control, double x, double y, TimeSpan duration)
        {
            if (!double.IsNaN(x))
            {
                var from = GraphCanvas.GetX(control);
                from = double.IsNaN(from) ? 0.0 : from;

                //create the animation for the horizontal position
                var animationX = new DoubleAnimation(
                    from,
                    x,
                    duration,
                    FillBehavior.HoldEnd);
                animationX.Completed += (s, e) =>
                {
                    control.BeginAnimation(GraphCanvas.XProperty, null);
                    control.SetValue(GraphCanvas.XProperty, x);
                };
                control.BeginAnimation(GraphCanvas.XProperty, animationX, HandoffBehavior.Compose);
            }
            if (!double.IsNaN(y))
            {
                var from = GraphCanvas.GetY(control);
                from = double.IsNaN(from) ? 0.0 : from;

                //create an animation for the vertical position
                var animationY = new DoubleAnimation(
                    from, y,
                    duration,
                    FillBehavior.HoldEnd);
                animationY.Completed += (s, e) =>
                {
                    control.BeginAnimation(GraphCanvas.YProperty, null);
                    control.SetValue(GraphCanvas.YProperty, y);
                };
                control.BeginAnimation(GraphCanvas.YProperty, animationY, HandoffBehavior.Compose);
            }
        }
Example #7
0
        // Plays a quick fadeIn/fadeOut for the given control.
        private void DoConfirmationAnimation(Control control)
        {
            control.Visibility = Visibility.Visible;
            DoubleAnimation da = new DoubleAnimation();

            da.From       = 0;
            da.To         = 0.75;
            da.Duration   = new Duration(TimeSpan.FromSeconds(0.75));
            da.Completed += (s, e) =>
            {
                DoubleAnimation db = new DoubleAnimation();
                db.From       = 0.75;
                db.To         = 0;
                db.Duration   = new Duration(TimeSpan.FromSeconds(0.75));
                db.BeginTime  = TimeSpan.FromSeconds(0.5);
                db.Completed += (sender, eargs) =>
                {
                    control.Visibility = Visibility.Hidden;
                };
                control.BeginAnimation(OpacityProperty, db);
            };
            control.BeginAnimation(OpacityProperty, da);
        }
        /// <summary>
        /// Fades in control with an animation
        /// </summary>
        /// <param name="control">Control to be faded in</param>
        private void FadeInControl(Control control)
        {
            //Create and initialize DoubleAnimation object
            DoubleAnimation fadeIn = new DoubleAnimation();

            fadeIn.From      = 0.0;
            fadeIn.To        = 1.0;
            fadeIn.Duration  = TimeSpan.FromSeconds(FADE_TIME);
            fadeIn.BeginTime = TimeSpan.FromSeconds(0.0);

            //Enable control and animate
            control.IsEnabled = true;
            control.BeginAnimation(Control.OpacityProperty, fadeIn);
        }
Example #9
0
        /// <summary>
        /// 播放动画(DoubleAnimation)
        /// </summary>
        /// <param name="from">From</param>
        /// <param name="to">To</param>
        /// <param name="dp">依赖属性</param>
        /// <param name="target">对象</param>
        /// <param name="duration">时长</param>
        public static void PlayAnimation(double from, double to, DependencyProperty dp, Control target, double duration = 1)
        {
            DoubleAnimation animation = new DoubleAnimation()
            {
                From              = from,
                To                = to,
                Duration          = TimeSpan.FromSeconds(duration),
                FillBehavior      = FillBehavior.HoldEnd,
                AccelerationRatio = .5,
                EasingFunction    = CAAnimation.be
            };

            target.BeginAnimation(dp, animation);
        }
        /// <summary>
        /// Fades out the control with an animation
        /// </summary>
        /// <param name="control">Control to be faded out</param>
        private void FadeOutControl(Control control)
        {
            if (control.Opacity != 0.0)  //only do it if the control is not already faded out.
            {
                //Create and initialize DoubleAnimation object
                DoubleAnimation fadeOut = new DoubleAnimation();
                fadeOut.From      = 1.0;
                fadeOut.To        = 0.0;
                fadeOut.Duration  = TimeSpan.FromSeconds(FADE_TIME);
                fadeOut.BeginTime = TimeSpan.FromSeconds(0.0);

                //Animate and disable control
                control.BeginAnimation(Control.OpacityProperty, fadeOut);
                control.IsEnabled = false;
            }
        }
Example #11
0
        private void StartAppearAnimation(Control pControl)
        {
            TimeSpan        heightAnimationDuration = TimeSpan.FromMilliseconds(200);
            DoubleAnimation heightAnimation         = new DoubleAnimation(0, pControl.ActualHeight, new Duration(heightAnimationDuration));

            heightAnimation.Completed += (sender, args) => { pControl.Opacity = 1; };
            pControl.BeginAnimation(HeightProperty, heightAnimation);
            TranslateTransform translateTransform = new TranslateTransform();
            DoubleAnimation    marginAnimation    = new DoubleAnimation(-pControl.ActualWidth, 0, new Duration(TimeSpan.FromMilliseconds(200)))
            {
                BeginTime = heightAnimationDuration,
            };

            pControl.RenderTransform = translateTransform;
            translateTransform.BeginAnimation(TranslateTransform.XProperty, marginAnimation);
        }
Example #12
0
        public static void OpacityControl(Control control, double From, double To, double TimeSecond, double TimeMillisecond = 0)
        {
            QuinticEase EP = new QuinticEase();

            EP.EasingMode = EasingMode.EaseOut;

            var Dir = new DoubleAnimation
            {
                Duration       = new Duration(TimeSpan.FromSeconds(TimeSecond)),
                From           = From,
                To             = To,
                BeginTime      = TimeSpan.FromMilliseconds(TimeMillisecond),
                EasingFunction = EP,
                AutoReverse    = false
            };

            control.BeginAnimation(UIElement.OpacityProperty, Dir);
        }
Example #13
0
        /// <summary>
        /// Use this method to make an animation for a window in X axis
        /// </summary>
        /// <param name="cntrl">The targhetting window</param>
        /// <param name="FromXPos">The position before the final position</param>
        /// <param name="XPos">The final position</param>
        /// <param name="TimeSecond">The duration on the animation</param>
        /// <param name="TimeMillisecond">The delay of the animation</param>
        public static void MoveWindowToTargetX(Control cntrl, double FromXPos, double XPos, double TimeSecond, double TimeMillisecond = 0)
        {
            QuadraticEase EP = new QuadraticEase();

            EP.EasingMode = EasingMode.EaseInOut;

            var DirX = new DoubleAnimation
            {
                Duration       = new Duration(TimeSpan.FromSeconds(TimeSecond)),
                From           = XPos - FromXPos,
                To             = XPos,
                BeginTime      = TimeSpan.FromMilliseconds(TimeMillisecond),
                EasingFunction = EP,
                AutoReverse    = false
            };

            cntrl.BeginAnimation(Window.TopProperty, DirX);
        }
 // Plays a quick fadeIn/fadeOut for the given control.
 private void DoConfirmationAnimation(Control control)
 {
     control.Visibility = Visibility.Visible;
     DoubleAnimation da = new DoubleAnimation();
     da.From = 0;
     da.To = 0.75;
     da.Duration = new Duration(TimeSpan.FromSeconds(0.75));
     da.Completed += (s, e) =>
     {
         DoubleAnimation db = new DoubleAnimation();
         db.From = 0.75;
         db.To = 0;
         db.Duration = new Duration(TimeSpan.FromSeconds(0.75));
         db.BeginTime = TimeSpan.FromSeconds(0.5);
         db.Completed += (sender, eargs) =>
         {
             control.Visibility = Visibility.Hidden;
         };
         control.BeginAnimation(OpacityProperty, db);
     };
     control.BeginAnimation(OpacityProperty, da);
 }
Example #15
0
        private void FadeAnimation(Control AnimationObject, double start, double end)
        {
            DoubleAnimation da = new DoubleAnimation(start, end, TimeSpan.FromMilliseconds(200));

            AnimationObject.BeginAnimation(Control.OpacityProperty, da);
        }