Пример #1
0
        /// <summary>
        /// Perform the animation when the child's height has changed.
        /// </summary>
        /// <param name="h"></param>
        /// <returns></returns>
        private double AnimatedResize(Double h)
        {
            double delta = targetHeight - h;

            Animation.Animation animation = HeightAnimation as Animation.Animation;
            if (animation == null)
            {
                animation = CreateAnimation();
            }
            targetHeight = h;
            //animation.From = delta;
            //animation.To = 0;
            //this.BeginAnimation(AnimationDecorator.HeightOffsetProperty, animation);
            animation.FillMode = FillMode.Backward;
            KeyFrame keyFrame = new KeyFrame();

            keyFrame.Cue = new Cue(0);
            keyFrame.Setters.Add(new Setter(AnimationDecorator.HeightOffsetProperty, delta));
            animation.Children.Add(keyFrame);
            keyFrame     = new KeyFrame();
            keyFrame.Cue = new Cue(1);
            keyFrame.Setters.Add(new Setter(AnimationDecorator.HeightOffsetProperty, 0));
            animation.Children.Add(keyFrame);

            animation.RunAsync(this);
            return(delta);
        }
Пример #2
0
        private async void AnimateExpandedChanged(bool expanded)
        {
            if (Child != null)
            {
                animating = true;

                if (YOffset > 0)
                {
                    YOffset = 0;
                }
                if (-YOffset > Child.DesiredSize.Height)
                {
                    YOffset = -Child.DesiredSize.Height;
                }
                Animation.Animation animation = HeightAnimation as Animation.Animation;
                if (animation == null)
                {
                    animation = CreateAnimation();
                }

                animation.FillMode = expanded ? FillMode.Forward : FillMode.Backward;

                double val = expanded ? 0 : -Child.DesiredSize.Height;

                KeyFrame keyFrame = null;

                if (expanded)
                {
                    keyFrame     = new KeyFrame();
                    keyFrame.Cue = new Cue(0);
                    keyFrame.Setters.Add(new Setter(AnimationDecorator.YOffsetProperty, YOffset));
                    animation.Children.Add(keyFrame);
                    keyFrame     = new KeyFrame();
                    keyFrame.Cue = new Cue(1);
                    keyFrame.Setters.Add(new Setter(AnimationDecorator.YOffsetProperty, val));
                    animation.Children.Add(keyFrame);
                }
                else
                {
                    keyFrame     = new KeyFrame();
                    keyFrame.Cue = new Cue(1);
                    keyFrame.Setters.Add(new Setter(AnimationDecorator.YOffsetProperty, val));
                    animation.Children.Add(keyFrame);

                    keyFrame     = new KeyFrame();
                    keyFrame.Cue = new Cue(0);
                    keyFrame.Setters.Add(new Setter(AnimationDecorator.YOffsetProperty, 1d));
                    animation.Children.Add(keyFrame);
                }

                //animation.From = null;
                //animation.To =
                //animation.Completed += new EventHandler(animation_Completed);

                //this.BeginAnimation(AnimationDecorator.YOffsetProperty, animation);

                if (OpacityAnimation)
                {
                    val = expanded ? 1 : 0;

                    keyFrame.Setters.Add(new Setter(AnimationDecorator.AnimationOpacityProperty, val));
                    animation.Children.Add(keyFrame);
                    //this.BeginAnimation(AnimationDecorator.AnimationOpacityProperty, animation);
                }

                await Task.WhenAll(new Task[] { animation.RunAsync(this) }).ContinueWith(x =>
                {
                    animating = false;
                });
            }
            else
            {
                YOffset = int.MinValue;
            }
        }