/// <summary>
 /// Animates a control and allows control of the duration and opacity
 /// </summary>
 /// <param name="control">The control to be animated</param>
 /// <param name="opacity">The opacity value for the animation</param>
 /// <param name="duration">The duration for the animation</param>
 private void animateControlOpacity(Control control, double opacity, double duration)
 {
     control.BeginInit();
     control.Dispatcher.BeginInvoke((Action)(() =>
     {
         DoubleAnimation controlAnimation = new DoubleAnimation(opacity, new Duration(TimeSpan.FromSeconds(duration)));
         control.BeginAnimation(Label.OpacityProperty, controlAnimation);
     }), null);
     control.EndInit();
 }
示例#2
0
        /// <summary>
        /// 界面淡出
        /// </summary>
        /// <param name="window"></param>
        /// <param name="second">淡出时间</param>
        public static void Fade_Out_Window(System.Windows.Controls.Control window, double second)
        {
            DoubleAnimation da = new DoubleAnimation
            {
                From     = 1,                           //起始值
                To       = 0,                           //结束值
                Duration = TimeSpan.FromSeconds(second) //动画持续时间
            };

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

            control.BeginAnimation(UIElement.OpacityProperty, da);//开始动画
        }
示例#4
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);
 }
示例#5
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);
     }
 }
        void Transition(Control outItem, Control inItem)
        {
            if (_transitionInProgress)
            {
                _transitionQueueOut.Enqueue(outItem);
                _transitionQueueIn.Enqueue(inItem);
            }
            else
            {
                _transitionInProgress = true;

                inItem.Opacity = 0;
                inItem.Visibility = Visibility.Visible;
                outItem.IsEnabled = false;

                DoubleAnimation daFadeOut = new DoubleAnimation();
                daFadeOut.To = 0;
                daFadeOut.Duration = TimeSpan.FromMilliseconds(1000);
                daFadeOut.Completed += delegate(object sender, EventArgs e)
                {
                    inItem.IsEnabled = true;
                    outItem.Visibility = Visibility.Collapsed;
                    _transitionInProgress = false;

                    if (_transitionQueueIn.Count > 0)
                    {
                        Transition(_transitionQueueOut.Dequeue(), _transitionQueueIn.Dequeue());
                    }
                };

                DoubleAnimation daFadeIn = new DoubleAnimation();
                daFadeIn.To = 1;
                daFadeIn.Duration = TimeSpan.FromMilliseconds(1000);

                outItem.BeginAnimation(FrameworkElement.OpacityProperty, daFadeOut);
                inItem.BeginAnimation(FrameworkElement.OpacityProperty, daFadeIn);
            }
        }
 public static void Fade_Out_Control(Control c, int seconds)
 {
     Duration dur = new Duration(new TimeSpan(0, 0, 0, 0, seconds));
     fadeOut.Duration = dur;
     c.BeginAnimation(Control.OpacityProperty, fadeOut);
 }
示例#8
0
 public static void FadeScrollElement(double fromValue, double toValue, Control control)
 {
     DoubleAnimation da = new DoubleAnimation(fromValue, toValue, time);
     da.DecelerationRatio = acceleration;
     control.BeginAnimation(Control.OpacityProperty, da);
 }
示例#9
0
 public static void SizeHeight(double fromValue, double toValue, Control control)
 {
     DoubleAnimation da = new DoubleAnimation(fromValue, toValue, time);
     da.DecelerationRatio = acceleration;
     control.BeginAnimation(Control.HeightProperty, da);
 }
示例#10
0
 private void HideAnimation(Control AnimationObject, double start, double end)
 {
     DoubleAnimation da = new DoubleAnimation(start, end, TimeSpan.FromMilliseconds(200));
     AnimationObject.BeginAnimation(Control.WidthProperty, da);
 }