public SmoothScrollViewer()
        {
            initFrame = new DiscreteDoubleKeyFrame()
            {
                KeyTime = TimeSpan.Zero
            };
            beginFrame = new LinearDoubleKeyFrame()
            {
                KeyTime = TimeSpan.FromMilliseconds(60)
            };
            endFrame = new LinearDoubleKeyFrame()
            {
                KeyTime = TimeSpan.FromMilliseconds(150)
            };
            scrollFrames = new DoubleAnimationUsingKeyFrames();
            scrollFrames.KeyFrames.Add(initFrame);
            scrollFrames.KeyFrames.Add(beginFrame);
            scrollFrames.KeyFrames.Add(endFrame);

            scrollStoryboard = new Storyboard();
            scrollStoryboard.Children.Add(scrollFrames);
            Storyboard.SetTarget(scrollFrames, this);
            Storyboard.SetTargetProperty(scrollFrames, new PropertyPath(SmoothScrollViewer.OffsetProperty));
            scrollStoryboard.Completed += OnStoryboardCompleted;
        }
Exemple #2
0
        private void PlayAnimation()
        {
            const int    nFlashCount = 3, nTotalCount = nFlashCount * 2;
            const double dFrameTime = 0.3;

            DoubleAnimationUsingKeyFrames anim         = new DoubleAnimationUsingKeyFrames();
            DoubleKeyFrameCollection      kfCollection = new DoubleKeyFrameCollection();


            double dCurTime = 0.0;

            for (int i = 0; i < nTotalCount; i++)
            {
                DoubleKeyFrame keyFrame = new DiscreteDoubleKeyFrame();

                keyFrame.KeyTime = TimeSpan.FromSeconds(dCurTime);
                keyFrame.Value   = (i % 2 == 0) ? 0.75 : 0;

                kfCollection.Add(keyFrame);

                dCurTime += (i == 0 && !m_bValid) ? 1.0 : dFrameTime;
            }

            anim.KeyFrames  = kfCollection;
            anim.Duration   = TimeSpan.FromSeconds(dCurTime);
            anim.Completed += OnAnimationCompleted;

            m_animImg.BeginAnimation(Image.OpacityProperty, anim);
            m_bIgnoreAnimEnd = false;
        }
Exemple #3
0
        private DoubleAnimationUsingKeyFrames GetTimeline(double y)
        {
            DoubleAnimationUsingKeyFrames daTranslate = new DoubleAnimationUsingKeyFrames();

            Storyboard.SetTargetProperty(daTranslate, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)"));
            Storyboard.SetTarget(daTranslate, this);
            DiscreteDoubleKeyFrame keyframe2_1 = new DiscreteDoubleKeyFrame()
            {
                KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)),
                Value   = y + LINEHEGHT
            };
            DiscreteDoubleKeyFrame keyframe2_2 = new DiscreteDoubleKeyFrame()
            {
                KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.4)),
                Value   = y + LINEHEGHT
            };
            EasingDoubleKeyFrame keyframe2_3 = new EasingDoubleKeyFrame()
            {
                KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.8)),
                Value   = y
            };

            keyframe2_3.EasingFunction = new CubicEase()
            {
                EasingMode = EasingMode.EaseOut
            };
            daTranslate.KeyFrames.Add(keyframe2_1);
            daTranslate.KeyFrames.Add(keyframe2_2);
            daTranslate.KeyFrames.Add(keyframe2_3);
            return(daTranslate);
        }
Exemple #4
0
        private void AddRenderTransform(UIElement line, double startPosition)
        {
            TransformGroup     tg        = new TransformGroup();
            TranslateTransform translate = new TranslateTransform();

            translate.Y = startPosition;
            tg.Children.Add(translate);
            line.RenderTransform = tg;

            DoubleAnimationUsingKeyFrames da   = new DoubleAnimationUsingKeyFrames();
            SplineDoubleKeyFrame          sdkf = new SplineDoubleKeyFrame();

            sdkf.KeyTime   = TimeSpan.FromSeconds(.5);
            sdkf.KeySpline = new KeySpline();
            sdkf.KeySpline.ControlPoint1 = new Point(0.80, 0.004);
            sdkf.KeySpline.ControlPoint1 = new Point(0.080, 1);

            sdkf.Value = startPosition - 20;
            da.KeyFrames.Add(sdkf);
            Storyboard.SetTarget(da, translate);
            Storyboard.SetTargetProperty(da, new PropertyPath("(Y)"));

            DiscreteDoubleKeyFrame ddkf = new DiscreteDoubleKeyFrame();

            ddkf.KeyTime = TimeSpan.FromSeconds(_Speed);
            ddkf.Value   = startPosition - 20;
            da.KeyFrames.Add(ddkf);

            _sb.Children.Add(da);

            _doubleAnimations.Add(line, da);
        }
        private void OnCatLoaded(object sender, RoutedEventArgs e)
        {
            var transform  = (sender as Image).RenderTransform as CompositeTransform;
            var storyboard = new Storyboard
            {
                FillBehavior   = FillBehavior.Stop,
                RepeatBehavior = RepeatBehavior.Forever
            };

            var keyFrames = new DoubleAnimationUsingKeyFrames();

            Storyboard.SetTarget(keyFrames, transform);
            Storyboard.SetTargetProperty(keyFrames, nameof(CompositeTransform.TranslateY));
            for (var i = 0; i < 12; i++)
            {
                var keyFrame = new DiscreteDoubleKeyFrame
                {
                    KeyTime = TimeSpan.FromSeconds((i + 1d) / 12d),
                    Value   = -(i + 1) * 2391d / 12d
                };
                keyFrames.KeyFrames.Add(keyFrame);
            }
            storyboard.Children.Add(keyFrames);
            storyboard.Begin();
        }
Exemple #6
0
        public void WrongAnimation()
        {
            const int    nFlashCount = 3, nTotalCount = nFlashCount * 2;
            const double dFrameTime = 0.3;

            Image img = (Image)this.GetTemplateChild("ButtonAnimImage");
            DoubleAnimationUsingKeyFrames anim         = new DoubleAnimationUsingKeyFrames();
            DoubleKeyFrameCollection      kfCollection = new DoubleKeyFrameCollection();

            EnableState(CmpButtonState.CBS_DISABLED);

            img.Source  = m_WrongImage;
            img.Opacity = 0.0;

            double dCurTime = 0.0;

            for (int i = 0; i < nTotalCount; i++)
            {
                DoubleKeyFrame keyFrame = new DiscreteDoubleKeyFrame();

                keyFrame.KeyTime = TimeSpan.FromSeconds(dCurTime);
                keyFrame.Value   = (i % 2 == 0) ? 0.75 : 0;

                kfCollection.Add(keyFrame);

                dCurTime += (i == 0) ? 1.0 : dFrameTime;
            }

            anim.KeyFrames  = kfCollection;
            anim.Duration   = TimeSpan.FromSeconds(dCurTime);
            anim.Completed += OnWrongAnimationComplete;

            img.BeginAnimation(Image.OpacityProperty, anim);
            m_bIgnoreAnimEnd = false;
        }
Exemple #7
0
        public override void OnApplyTemplate()
        {
            Expand_Trans_A1    = GetTemplateChild("Expand_Trans_A1") as DoubleAnimationUsingKeyFrames;
            Expand_Trans_A2    = GetTemplateChild("Expand_Trans_A2") as DoubleAnimationUsingKeyFrames;
            Collapsed_Trans_A1 = GetTemplateChild("Collapsed_Trans_A1") as DoubleAnimationUsingKeyFrames;
            Collapsed_Trans_A2 = GetTemplateChild("Collapsed_Trans_A2") as DoubleAnimationUsingKeyFrames;

            //Expand_A1 = GetTemplateChild("Expand_A1") as DoubleAnimationUsingKeyFrames;
            Expand_A2 = GetTemplateChild("Expand_A2") as DoubleAnimationUsingKeyFrames;
            //Collapsed_A1 = GetTemplateChild("Collapsed_A1") as DoubleAnimationUsingKeyFrames;
            Collapsed_A2 = GetTemplateChild("Collapsed_A2") as DoubleAnimationUsingKeyFrames;

            Expand_Trans_F1    = GetTemplateChild("Expand_Trans_F1") as SplineDoubleKeyFrame;
            Expand_Trans_F3    = GetTemplateChild("Expand_Trans_F3") as DiscreteDoubleKeyFrame;
            Collapsed_Trans_F1 = GetTemplateChild("Collapsed_Trans_F1") as SplineDoubleKeyFrame;
            Collapsed_Trans_F3 = GetTemplateChild("Collapsed_Trans_F3") as DiscreteDoubleKeyFrame;
            Expand_Trans_F2    = GetTemplateChild("Expand_Trans_F2") as DiscreteDoubleKeyFrame;
            Collapsed_Trans_F2 = GetTemplateChild("Collapsed_Trans_F2") as DiscreteDoubleKeyFrame;
            //Expand_F1 = GetTemplateChild("Expand_F1") as DiscreteDoubleKeyFrame;
            Expand_F2 = GetTemplateChild("Expand_F2") as DiscreteDoubleKeyFrame;
            //Collapsed_F1 = GetTemplateChild("Collapsed_F1") as DiscreteDoubleKeyFrame;
            Collapsed_F2 = GetTemplateChild("Collapsed_F2") as DiscreteDoubleKeyFrame;


            ClipMask = GetTemplateChild("ClipMask") as RectangleGeometry;
            base.OnApplyTemplate();

            var root = GetTemplateChild("rootborder") as FrameworkElement;

            _visualstates = VisualStateManager.GetVisualStateGroups(root)[0] as VisualStateGroup;
        }
Exemple #8
0
        private static DoubleKeyFrame CreateDoubleKeyFrmas(KeyFrames <double> Model)
        {
            DoubleKeyFrame frame = null;

            switch (Model.Type)
            {
            case KeyFramesType.Spline: frame = new SplineDoubleKeyFrame()
            {
                    KeySpline = Model.Spline
            }; break;

            case KeyFramesType.Linear: frame = new LinearDoubleKeyFrame(); break;

            case KeyFramesType.Easing: frame = new EasingDoubleKeyFrame()
            {
                    EasingFunction = Model.EasingFunction
            }; break;

            case KeyFramesType.Discrete: frame = new DiscreteDoubleKeyFrame(); break;

            default: break;
            }
            frame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(Model.KeyTime));
            frame.Value   = Model.Value;
            return(frame);
        }
        /// <summary>
        /// 获取模板控件
        /// </summary>
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            _valuePanel = GetTemplateChild("ValuePanel") as Path;
            _backPanel  = GetTemplateChild("BackPanel") as Path;
            if (_valuePanel is null)
            {
                _valuePanel = GetTemplateChild("ValuePanel") as Rectangle;
                _backPanel  = GetTemplateChild("BackPanel") as Rectangle;

                _e1frame1 = GetTemplateChild("E1Frame1") as SplineDoubleKeyFrame;
                _e1frame2 = GetTemplateChild("E1Frame2") as DiscreteDoubleKeyFrame;
                _e1frame3 = GetTemplateChild("E1Frame3") as SplineDoubleKeyFrame;

                _e2frame1 = GetTemplateChild("E2Frame1") as SplineDoubleKeyFrame;
                _e2frame2 = GetTemplateChild("E2Frame2") as DiscreteDoubleKeyFrame;
                _e2frame3 = GetTemplateChild("E2Frame3") as SplineDoubleKeyFrame;

                _e3frame1 = GetTemplateChild("E3Frame1") as SplineDoubleKeyFrame;
                _e3frame2 = GetTemplateChild("E3Frame2") as DiscreteDoubleKeyFrame;
                _e3frame3 = GetTemplateChild("E3Frame3") as SplineDoubleKeyFrame;

                _e4frame1 = GetTemplateChild("E4Frame1") as SplineDoubleKeyFrame;
                _e4frame2 = GetTemplateChild("E4Frame2") as DiscreteDoubleKeyFrame;
                _e4frame3 = GetTemplateChild("E4Frame3") as SplineDoubleKeyFrame;

                _e5frame1 = GetTemplateChild("E5Frame1") as SplineDoubleKeyFrame;
                _e5frame2 = GetTemplateChild("E5Frame2") as DiscreteDoubleKeyFrame;
                _e5frame3 = GetTemplateChild("E5Frame3") as SplineDoubleKeyFrame;

                _panelmove = GetTemplateChild("PanelMove") as DoubleAnimation;
            }
        }
        private Timeline CreateExpandIn(ITransitionEffectSubject effectSubject)
        {
            var scaleXAnimation = new DoubleAnimationUsingKeyFrames();
            var zeroFrame       = new DiscreteDoubleKeyFrame(0.0);
            var startFrame      = new DiscreteDoubleKeyFrame(.5, effectSubject.Offset + OffsetTime);
            var endFrame        = new EasingDoubleKeyFrame(1, effectSubject.Offset + OffsetTime + Duration)
            {
                EasingFunction = new SineEase()
            };

            scaleXAnimation.KeyFrames.Add(zeroFrame);
            scaleXAnimation.KeyFrames.Add(startFrame);
            scaleXAnimation.KeyFrames.Add(endFrame);

            Storyboard.SetTargetName(scaleXAnimation, effectSubject.ScaleTransformName);
            Storyboard.SetTargetProperty(scaleXAnimation, new PropertyPath(ScaleTransform.ScaleXProperty));

            var scaleYAnimation = scaleXAnimation.Clone();

            Storyboard.SetTargetName(scaleYAnimation, effectSubject.ScaleTransformName);
            Storyboard.SetTargetProperty(scaleYAnimation, new PropertyPath(ScaleTransform.ScaleYProperty));

            var parallelTimeline = new ParallelTimeline();

            parallelTimeline.Children.Add(scaleXAnimation);
            parallelTimeline.Children.Add(scaleYAnimation);

            return(parallelTimeline);
        }
        private void OnHeartLoaded(object sender, RoutedEventArgs e)
        {
            _heartTransform  = (sender as Image).RenderTransform as CompositeTransform;
            _checkStoryboard = new Storyboard();


            var keyFrames = new DoubleAnimationUsingKeyFrames();

            Storyboard.SetTarget(keyFrames, _heartTransform);
            Storyboard.SetTargetProperty(keyFrames, nameof(CompositeTransform.TranslateX));
            TimeSpan start = TimeSpan.Zero;

            for (var i = 0; i < 28; i++)
            {
                var keyFrame = new DiscreteDoubleKeyFrame
                {
                    KeyTime = TimeSpan.FromSeconds((i + 1d) / 28d),
                    Value   = -(i + 1) * 100
                };
                keyFrames.KeyFrames.Add(keyFrame);
            }

            _checkStoryboard.Children.Add(keyFrames);

            _checkStoryboard.FillBehavior = FillBehavior.HoldEnd;
        }
Exemple #12
0
        private TimeSpan AnimateFlip(Storyboard sb, ScaleTransform scale,
                                     out TimeSpan tsLastFrame)
        {
            double speed        = 4;
            double flipRotation = 0;
            double flipped      = 2;

            tsLastFrame = new TimeSpan();
            TimeSpan tsSideFlipped = new TimeSpan();

            int frames = 1;
            DoubleAnimationUsingKeyFrames daX =
                new DoubleAnimationUsingKeyFrames();

            tsLastFrame = new TimeSpan();
            while (flipRotation != flipped * 180)
            {
                flipRotation += speed;
                double flipRadian = flipRotation * (Math.PI / 180);
                double size       = Math.Cos(flipRadian);
                double scalar     = (1 / (1 / size));

                DiscreteDoubleKeyFrame ddkfX = new DiscreteDoubleKeyFrame();
                ddkfX.Value = (size * scalar);

                tsLastFrame = TimeSpan.FromMilliseconds(frames * 7);

                //the first time we flip to negative capture the
                //tsLastFrame so we know when we will need to
                //visualize the flip side
                flipped = (size < 0) ? +1 : +0;
                if (flipped == 1 && tsSideFlipped.Ticks == 0)
                {
                    tsSideFlipped = tsLastFrame;
                }

                ddkfX.KeyTime = KeyTime.FromTimeSpan(tsLastFrame);

                //add the DiscreteDoubleKeyFrame to the
                //DoubleAnimationUsingKeyFrames
                daX.KeyFrames.Add(ddkfX);

                flipRotation %= 360;
                frames++;
            }

            Storyboard.SetTarget(daX, scale);
            Storyboard.SetTargetProperty(daX, new PropertyPath("(ScaleX)"));
            sb.Children.Add(daX);

            VisualizeSide(sb, tsSideFlipped, 0, TimeSpan.FromMilliseconds
                              ((tsSideFlipped.Milliseconds + 100)),
                          back.Opacity, this.back);
            VisualizeSide(sb, TimeSpan.FromMilliseconds((
                                                            tsSideFlipped.Milliseconds - 100)), front.Opacity,
                          tsSideFlipped, 0, this.front);
            back.Opacity = 0;
            return(tsLastFrame);
        }
Exemple #13
0
        public override void OnApplyTemplate()
        {
            _ContentTranslate_Expand       = GetTemplateChild("ContentTranslate_Expand") as DoubleAnimationUsingKeyFrames;
            _ContentTranslate_Collapsed    = GetTemplateChild("ContentTranslate_Collapsed") as DoubleAnimationUsingKeyFrames;
            _Expand_Transition             = GetTemplateChild("Expand_Transition") as DoubleAnimationUsingKeyFrames;
            _Collapsed_Transition          = GetTemplateChild("Collapsed_Transition") as DoubleAnimationUsingKeyFrames;
            _ContentTranslate_Collapsed_F1 = GetTemplateChild("ContentTranslate_Collapsed_F1") as DiscreteDoubleKeyFrame;
            _Collapsed_Transition_F1       = GetTemplateChild("Collapsed_Transition_F1") as SplineDoubleKeyFrame;

            base.OnApplyTemplate();
            ChangeOrientation();
        }
Exemple #14
0
    private void AnimateCurrentItem(int currIndex)
    {
        Console.WriteLine("AnimateCurreintItem, currIndex: " + currIndex);
        var gen = listViewCombined.ItemContainerGenerator;
        var obj = (gen.ContainerFromItem(listViewCombined.Items[currIndex]));

        if (obj != null)
        {
            ListViewItem     myListBoxItem      = (ListViewItem)obj;
            ContentPresenter myContentPresenter = FindVisualChild <ContentPresenter>(myListBoxItem);
            DataTemplate     myDataTemplate     = myContentPresenter.ContentTemplate;
            Image            promptImage        = (Image)myDataTemplate.FindName("PromptImage", myContentPresenter);
            Image            targetImage        = (Image)myDataTemplate.FindName("TargetImage", myContentPresenter);
            this.UnregisterName(listViewCombined.Name);
            this.UnregisterName(promptImage.Name);
            this.UnregisterName(targetImage.Name);
            this.RegisterName(listViewCombined.Name, listViewCombined);
            this.RegisterName(promptImage.Name, promptImage);
            this.RegisterName(targetImage.Name, targetImage);
            DoubleAnimation promptAni = new DoubleAnimation();
            promptAni.From     = 1;
            promptAni.To       = 0;
            promptAni.Duration = new Duration(TimeSpan.FromMilliseconds(4000));
            sbPrompt           = new Storyboard();
            sbPrompt.Children.Add(promptAni);
            Storyboard.SetTargetName(promptAni, promptImage.Name);
            Storyboard.SetTargetProperty(promptAni, new PropertyPath(Image.OpacityProperty));
            DoubleAnimationUsingKeyFrames targetAni = new DoubleAnimationUsingKeyFrames();
            var kf1 = new DiscreteDoubleKeyFrame(0.25, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)));
            var kf2 = new DiscreteDoubleKeyFrame(1, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(2)));
            var kf3 = new DiscreteDoubleKeyFrame(0.25, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(4)));
            targetAni.KeyFrames.Add(kf1);
            targetAni.KeyFrames.Add(kf2);
            targetAni.KeyFrames.Add(kf3);
            if (sbTarget != null)
            {
                sbTarget.Completed -= Storyboard_Completed_1;
            }
            sbTarget            = new Storyboard();
            sbTarget.Completed += Storyboard_Completed_1;
            sbTarget.Children.Add(targetAni);
            Storyboard.SetTargetName(targetAni, targetImage.Name);
            Storyboard.SetTargetProperty(targetAni, new PropertyPath(Image.OpacityProperty));
            sbPrompt.Begin(this, true);
            sbTarget.Begin(this, true);
        }
        else
        {
            ;
        }
    }
Exemple #15
0
        /// <summary>
        /// Update the seconds animation to add one second ticks
        /// </summary>
        /// <param name="animation">the animation</param>
        private static void UpdateSecondAnimation(DoubleAnimationUsingKeyFrames animation)
        {
            animation.KeyFrames.Clear();

            for (var i = 0; i <= 60; i++)
            {
                var keyFrame = new DiscreteDoubleKeyFrame()
                {
                    KeyTime = new TimeSpan(0, 0, i),
                    Value   = i * 6
                };

                animation.KeyFrames.Add(keyFrame);
            }
        }
        private Timeline CreateSlide(double from, double to, TimeSpan initialOffset)
        {
            var zeroFrame  = new DiscreteDoubleKeyFrame(from);
            var startFrame = new DiscreteDoubleKeyFrame(from, initialOffset + OffsetTime);
            var endFrame   = new EasingDoubleKeyFrame(to, initialOffset + OffsetTime + Duration)
            {
                EasingFunction = new SineEase()
            };
            var slideAnimation = new DoubleAnimationUsingKeyFrames();

            slideAnimation.KeyFrames.Add(zeroFrame);
            slideAnimation.KeyFrames.Add(startFrame);
            slideAnimation.KeyFrames.Add(endFrame);

            return(slideAnimation);
        }
Exemple #17
0
        protected override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            _selectionIndicator                    = GetTemplateChild(SelectionIndicatorName) as UIElement;
            _selectionIndicatorScaleFrame          = GetTemplateChild(SelectionIndicatorScaleFrameName) as EasingDoubleKeyFrame;
            _selectionIndicatorStoryboard          = GetTemplateChild(SelectionIndicatorAnimationName) as Storyboard;
            _selectionIndicatorFadeStoryboard      = GetTemplateChild(SelectionIndicatorFadeAnimationName) as Storyboard;
            _selectionIndicatorTranslateStartFrame = GetTemplateChild(SelectionIndicatorTranslateStartFrameName) as DiscreteDoubleKeyFrame;
            _selectionIndicatorTranslateEndFrame   = GetTemplateChild(SelectionIndicatorTranslateEndFrameName) as LinearDoubleKeyFrame;
            _selectionIndicatorTransform           = GetTemplateChild(SelectionIndicatorTransformName) as CompositeTransform;
            _selectionIndicatorCenterStartFrame    = GetTemplateChild(SelectionIndicatorCenterStartFrameName) as DiscreteDoubleKeyFrame;
            _selectionIndicatorCenterEndFrame      = GetTemplateChild(SelectionIndicatorCenterEndFrameName) as LinearDoubleKeyFrame;

            UpdateLocalVisualState();
        }
        public static DoubleAnimationUsingKeyFrames AddDiscreteKeyFrame(
            this DoubleAnimationUsingKeyFrames animation,
            double seconds, double value)
        {
            var keyFrame = new DiscreteDoubleKeyFrame
            {
                KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(seconds)),
                Value   = value
            };

            animation.KeyFrames.Add(keyFrame);
#if NETFX_CORE || WINDOWS_81_PORTABLE
            animation.EnableDependentAnimation = true;
#endif
            return(animation);
        }
Exemple #19
0
        /// <summary>
        /// Registers all the animation definitions into a static property
        /// </summary>
        private void RegisterAnimations()
        {
            Uri uri = new Uri(animationsResourceUri, UriKind.RelativeOrAbsolute);
            StreamResourceInfo info = Application.GetResourceStream(uri);

            List <Animation> storedAnimations = Newtonsoft.Json.JsonConvert.DeserializeObject <List <Animation> >(StreamToString(info.Stream));

            Animations = new Dictionary <string, Tuple <DoubleAnimationUsingKeyFrames, DoubleAnimationUsingKeyFrames> >();

            foreach (Animation animation in storedAnimations)
            {
                DoubleAnimationUsingKeyFrames xDoubleAnimation = new DoubleAnimationUsingKeyFrames();
                xDoubleAnimation.FillBehavior = FillBehavior.HoldEnd;

                DoubleAnimationUsingKeyFrames yDoubleAnimation = new DoubleAnimationUsingKeyFrames();
                yDoubleAnimation.FillBehavior = FillBehavior.HoldEnd;

                int    lastCol    = 0;
                int    lastRow    = 0;
                double timeOffset = 0;

                foreach (Recoding.ClippyVSPackage.Configurations.Frame frame in animation.Frames)
                {
                    if (frame.ImagesOffsets != null)
                    {
                        lastCol = frame.ImagesOffsets.Column;
                        lastRow = frame.ImagesOffsets.Row;
                    }

                    // X
                    DiscreteDoubleKeyFrame xKeyFrame = new DiscreteDoubleKeyFrame(ClipWidth * -lastCol, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(timeOffset)));

                    // Y
                    DiscreteDoubleKeyFrame yKeyFrame = new DiscreteDoubleKeyFrame(ClipHeight * -lastRow, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(timeOffset)));

                    timeOffset += ((double)frame.Duration / 1000);

                    xDoubleAnimation.KeyFrames.Add(xKeyFrame);
                    yDoubleAnimation.KeyFrames.Add(yKeyFrame);
                }

                Animations.Add(animation.Name, new Tuple <DoubleAnimationUsingKeyFrames, DoubleAnimationUsingKeyFrames>(xDoubleAnimation, yDoubleAnimation));

                xDoubleAnimation.Completed += xDoubleAnimation_Completed;
            }
        }
Exemple #20
0
        /// <summary>
        /// アニメーションを更新します。
        /// </summary>
        private void UpdateAnimation()
        {
            _storyboard.Stop();

            if (this.Ellipse1 == null)
            {
                return;
            }
            if (double.IsNaN(this.ActualWidth))
            {
                return;
            }

            _initialKeyFrame = new DiscreteDoubleKeyFrame(-this.Ellipse1.ActualWidth, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(0)));
            var splineDoubleKeyFrame = new SplineDoubleKeyFrame(this.ActualWidth, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(3000)), new KeySpline(0.3, 0.85, 0.7, 0.15));

            _animation0_1.KeyFrames.Clear();
            _animation0_2.KeyFrames.Clear();
            _animation0_3.KeyFrames.Clear();
            _animation0_4.KeyFrames.Clear();
            _animation0_5.KeyFrames.Clear();

            _animation0_1.KeyFrames.Add(_initialKeyFrame);
            _animation0_2.KeyFrames.Add(_initialKeyFrame);
            _animation0_3.KeyFrames.Add(_initialKeyFrame);
            _animation0_4.KeyFrames.Add(_initialKeyFrame);
            _animation0_5.KeyFrames.Add(_initialKeyFrame);

            _animation1.KeyFrames.Clear();
            _animation2.KeyFrames.Clear();
            _animation3.KeyFrames.Clear();
            _animation4.KeyFrames.Clear();
            _animation5.KeyFrames.Clear();

            _animation1.KeyFrames.Add(splineDoubleKeyFrame);
            _animation2.KeyFrames.Add(splineDoubleKeyFrame);
            _animation3.KeyFrames.Add(splineDoubleKeyFrame);
            _animation4.KeyFrames.Add(splineDoubleKeyFrame);
            _animation5.KeyFrames.Add(splineDoubleKeyFrame);

            _storyboard.Begin();
        }
Exemple #21
0
        private DoubleAnimationUsingKeyFrames GetAnimation()
        {
            NameScope.SetNameScope(this, new NameScope());

            var animation = new DoubleAnimationUsingKeyFrames();

            for (int i = 0; i < NumberOfFrames; i++)
            {
                double         angle = i * 360.0 / NumberOfFrames;
                KeyTime        time  = KeyTime.FromPercent(((double)i) / NumberOfFrames);
                DoubleKeyFrame frame = new DiscreteDoubleKeyFrame(angle, time);
                animation.KeyFrames.Add(frame);
            }

            animation.Duration       = TimeSpan.FromSeconds(1 / RevolutionsPerSecond);
            animation.RepeatBehavior = RepeatBehavior.Forever;

            Storyboard.SetTargetName(animation, ANIMATION);
            Storyboard.SetTargetProperty(animation, new PropertyPath(RotateTransform.AngleProperty));

            return(animation);
        }
        private Timeline GetAnimation()
        {
            NameScope.SetNameScope(this, new NameScope());
            Timeline animation = null;

            if (UseKeyFrames)
            {
                animation = new DoubleAnimationUsingKeyFrames()
                {
                    RepeatBehavior = RepeatBehavior.Forever
                };

                for (int i = 0; i < NumberOfFrames; i++)
                {
                    var            angle = i * 360.0 / (double)NumberOfFrames;
                    var            time  = KeyTime.FromPercent((Convert.ToDouble(i)) / NumberOfFrames);
                    DoubleKeyFrame frame = new DiscreteDoubleKeyFrame(angle, time);
                    ((DoubleAnimationUsingKeyFrames)animation).KeyFrames.Add(frame);
                }
            }
            else
            {
                animation = new DoubleAnimation(0.0D, 360.0D, TimeSpan.FromSeconds(1 / RevolutionsPerSecond))
                {
                    RepeatBehavior = RepeatBehavior.Forever
                };

                if (NumberOfFrames != 16)
                {
                    Storyboard.SetDesiredFrameRate(animation, NumberOfFrames);
                }
            }

            Storyboard.SetTargetName(animation, string.Format("{0}{1}", m_AnimationName, ContentSpinner.ANIMATION));
            Storyboard.SetTargetProperty(animation, new PropertyPath(RotateTransform.AngleProperty));

            return(animation);
        }
Exemple #23
0
        private void InitializeEffect3D(Window window)
        {
            #region Viewport
            AxisAngleRotation3D angle = new AxisAngleRotation3D(new Vector3D(0, 1, 0), 0);
            ScaleTransform3D    scale = new ScaleTransform3D();
            Transform3DGroup    t3dg  = new Transform3DGroup();
            t3dg.Children.Add(scale);
            t3dg.Children.Add(new RotateTransform3D(angle));

            MeshGeometry3D mg3d = new MeshGeometry3D();
            mg3d.TriangleIndices    = new Int32Collection(new int[] { 0, 1, 2, 0, 2, 3 });
            mg3d.TextureCoordinates = new PointCollection(new Point[] { new Point(0, 0), new Point(0, 1), new Point(1, 1), new Point(1, 0), });

            Viewport2DVisual3D Viewport2d = new Viewport2DVisual3D();
            Viewport2d.Geometry = mg3d;
            Viewport2d.Material = new DiffuseMaterial(Brushes.White);
            Viewport2DVisual3D.SetIsVisualHostMaterial(Viewport2d.Material, true);
            Viewport2d.Transform = t3dg;

            Viewport3d        = new Viewport3D();
            Viewport3d.Camera = new PerspectiveCamera()
            {
                FieldOfView = 40
            };
            ModelVisual3D light1 = new ModelVisual3D();
            light1.Content = new DirectionalLight(Colors.White, new Vector3D(1, 1.733, -1));
            ModelVisual3D light2 = new ModelVisual3D();
            light2.Content = new DirectionalLight(Colors.White, new Vector3D(1, -1.733, -1));
            ModelVisual3D light3 = new ModelVisual3D();
            light3.Content = new DirectionalLight(Colors.White, new Vector3D(-2, 0, -1));
            Viewport3d.Children.Add(light1);
            Viewport3d.Children.Add(light2);
            Viewport3d.Children.Add(light3);
            Viewport3d.Children.Add(Viewport2d);
            #endregion
            #region Animation
            window.RegisterName("Viewport2d_Angle", angle);
            PropertyPath path = new PropertyPath(AxisAngleRotation3D.AngleProperty);
            DoubleAnimationUsingKeyFrames daukf = new DoubleAnimationUsingKeyFrames();
            Storyboard.SetTargetName(daukf, "Viewport2d_Angle");
            Storyboard.SetTargetProperty(daukf, path);

            SplineDoubleKeyFrame   KeyFrame1 = new SplineDoubleKeyFrame(90, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.25)), new KeySpline(0.7, 0.5, 0.3, 0.2));
            DiscreteDoubleKeyFrame KeyFrame2 = new DiscreteDoubleKeyFrame(-90, KeyTime.FromPercent(0.5));
            daukf.KeyFrames.Add(KeyFrame1);
            daukf.KeyFrames.Add(KeyFrame2);
            daukf.KeyFrames.Add(new SplineDoubleKeyFrame(0, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.5)), new KeySpline(0.2, 0.3, 0.5, 0.7)));

            Storyboard = new Storyboard();
            Storyboard.Children.Add(daukf);
            Storyboard.Completed += (sender, e) =>
            {
                try
                {
                    Viewport2d.Visual = null;
                    window.Content    = new_page;
                }
                catch { }
                finally { EffectEnable = true; }
            };

            angle.Changed += (sender, e) =>
            {
                if (angle.Angle < -70 && Viewport2d.Visual != this.new_page)
                {
                    try { Viewport2d.Visual = this.new_page; } catch { }
                }

                scale.ScaleX             = scale.ScaleY
                                         = 1 - Math.Abs(Math.Sin(angle.Angle / 180 * Math.PI) / 2.75);
            };
            #endregion
            #region Effect
            setTurnStyle = (isV, isX) =>
            {
                int v = isV ? -90 : 90;
                KeyFrame1.Value = v;
                KeyFrame2.Value = -v;
                int x = isX ? 1 : 0;
                angle.Axis = new Vector3D(x, 1 - x, 0);
            };

            effectBegin = (old_page, new_page) =>
            {
                Viewport3d.Width  = old_page.Width;
                Viewport3d.Height = old_page.Height;
                this.new_page     = new_page;
                window.Content    = Viewport3d;
                Viewport2d.Visual = old_page;
                EffectEnable      = false;
                ((PerspectiveCamera)Viewport3d.Camera).Position = new Point3D(0, 0, 2.75 * old_page.Width);
                setPositions(mg3d, old_page.RenderSize);
                Storyboard.Begin(window);
            };

            EffectEnable = true;
            #endregion
        }
        private void StartMarqueeAnimationIfNeeded(bool useTransitions = true)
        {
            var canvas = (Canvas)GetTemplateChild(CANVAS_NAME);

            if (canvas == null)
            {
                return;
            }

            // Change clip rectangle for new canvas size
            var rectanglegeometryClipCanvas = (RectangleGeometry)GetTemplateChild(RECT_GEOMETRY_CANVAS_NAME);

            if (rectanglegeometryClipCanvas != null)
            {
                rectanglegeometryClipCanvas.Rect = new Rect(0.0d, 0.0d, canvas.ActualWidth, canvas.ActualHeight);
            }

            if (this.IsStopped)
            {
                StopMarqueeAnimation(useTransitions);
                return;
            }

            // Add an animation handler
            var textblock = (TextBlock)GetTemplateChild(TEXTBLOCK_NAME);

            if (textblock != null)
            {
                // Animation is only needed if 'textblock' is larger than canvas
                if (textblock.ActualWidth > canvas.ActualWidth)
                {
                    var visualstateGroups  = VisualStateManager.GetVisualStateGroups(canvas).First();
                    var visualstateMarquee = visualstateGroups.States.Single(l => l.Name == VISUALSTATE_MARQUEE);
                    var storyboardMarquee  = new Storyboard()
                    {
                        AutoReverse    = !IsTicker,
                        Duration       = this.AnimationDuration,
                        RepeatBehavior = RepeatBehavior.Forever,
                        SpeedRatio     = this.AnimationSpeedRatio
                    };

                    if (IsTicker)
                    {
                        var animationMarquee = new DoubleAnimationUsingKeyFrames
                        {
                            AutoReverse    = storyboardMarquee.AutoReverse,
                            Duration       = storyboardMarquee.Duration,
                            RepeatBehavior = storyboardMarquee.RepeatBehavior,
                            SpeedRatio     = storyboardMarquee.SpeedRatio,
                        };
                        var frame1 = new DiscreteDoubleKeyFrame
                        {
                            KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)),
                            Value   = canvas.ActualWidth
                        };
                        var frame2 = new EasingDoubleKeyFrame
                        {
                            KeyTime        = KeyTime.FromTimeSpan(storyboardMarquee.Duration.TimeSpan),
                            Value          = -textblock.ActualWidth,
                            EasingFunction = this.EasingFunction
                        };

                        animationMarquee.KeyFrames.Add(frame1);
                        animationMarquee.KeyFrames.Add(frame2);

                        storyboardMarquee.Children.Add(animationMarquee);

                        Storyboard.SetTarget(animationMarquee, textblock.RenderTransform);
                        Storyboard.SetTargetProperty(animationMarquee, "(TranslateTransform.X)");
                    }
                    else
                    {
                        var animationMarquee = new DoubleAnimation
                        {
                            AutoReverse    = storyboardMarquee.AutoReverse,
                            Duration       = storyboardMarquee.Duration,
                            RepeatBehavior = storyboardMarquee.RepeatBehavior,
                            SpeedRatio     = storyboardMarquee.SpeedRatio,
                            From           = 0.0d,
                            To             = -textblock.ActualWidth,
                            EasingFunction = this.EasingFunction
                        };

                        storyboardMarquee.Children.Add(animationMarquee);

                        Storyboard.SetTarget(animationMarquee, textblock.RenderTransform);
                        Storyboard.SetTargetProperty(animationMarquee, "(TranslateTransform.X)");
                    }

                    visualstateMarquee.Storyboard = storyboardMarquee;

                    VisualStateManager.GoToState(this, VISUALSTATE_MARQUEE, useTransitions);
                }
            }
        }
        protected override Size ArrangeOverride(Size finalSize)
        {
            if (this.Children == null || this.Children.Count == 0)
            {
                return(finalSize);
            }

            TranslateTransform trans = null;

            double curX = 0;
            double curY = ItemTopMargin;

            double delta = SelectedItemLeftMargin;
            bool   init  = false;

            TimeSpan animationLength = TimeSpan.FromMilliseconds(this.AnimationDuration);

            int index = 0;

            foreach (ListBoxItem child in this.Children)
            {
                child.Arrange(new Rect(0, 0, child.DesiredSize.Width, child.DesiredSize.Height));

                trans = child.RenderTransform as TranslateTransform;

                if (trans == null)
                {
                    child.RenderTransformOrigin = new Point(0, 0);
                    trans = new TranslateTransform();
                    child.RenderTransform = trans;

                    double toX = curX + delta - (this.SelectedIndex * child.ActualWidth);
                    trans.X = toX;
                    trans.Y = curY - VerticalOffset;

                    trans.BeginAnimation(TranslateTransform.XProperty,
                                         new DoubleAnimation(toX, animationLength),
                                         HandoffBehavior.Compose);
                    trans.BeginAnimation(TranslateTransform.YProperty,
                                         new DoubleAnimation(curY - VerticalOffset, animationLength),
                                         HandoffBehavior.Compose);

                    init = true;
                }
                else
                {
                    //if (this.elementTimelineDictionary.ContainsKey(child))
                    //{
                    //    DoubleAnimationUsingKeyFrames frames = this.elementTimelineDictionary[child] as DoubleAnimationUsingKeyFrames;
                    //    trans.X = frames.KeyFrames[frames.KeyFrames.Count - 1].Value;
                    //    //     frames.SpeedRatio = 100;

                    //    //     Thread.Sleep(1);

                    //    //     trans.BeginAnimation(TranslateTransform.YProperty, null, HandoffBehavior.Compose);
                    //}
                }

                curX            += child.DesiredSize.Width;
                finalSize.Height = child.DesiredSize.Height;
            }

            if (init)
            {
                return(finalSize);
            }

            UIElement selectedItem = this.SelectedItem;

            if (selectedItem != null)
            {
                TranslateTransform selectedItemTrans = selectedItem.RenderTransform as TranslateTransform;
                delta = SelectedItemLeftMargin - selectedItemTrans.X;
                if (this.elementTimelineDictionary.ContainsKey(selectedItem))
                {
                    if (this.elementTimelineDictionary[selectedItem] is DoubleAnimationUsingKeyFrames)
                    {
                        DoubleAnimationUsingKeyFrames frames = this.elementTimelineDictionary[selectedItem] as DoubleAnimationUsingKeyFrames;
                        if (frames.KeyFrames.Count > 0)
                        {
                            delta = SelectedItemLeftMargin - frames.KeyFrames[frames.KeyFrames.Count - 1].Value;
                        }
                    }
                    else
                    {
                        DoubleAnimation doubleAnimation = this.elementTimelineDictionary[selectedItem] as DoubleAnimation;
                        if (doubleAnimation != null)
                        {
                            delta = SelectedItemLeftMargin - doubleAnimation.To.Value;
                        }
                    }
                }
            }

            if (delta == 0)
            {
                return(finalSize);
            }

            index = 0;
            if (this.CircleItems)
            {
                double             lastRight = this.SpaceAfterLastItem;
                TranslateTransform lastTrans = this.Children[this.Children.Count - 1].RenderTransform as TranslateTransform;
                lastRight = lastTrans.X + this.Children[this.Children.Count - 1].DesiredSize.Width;

                if (this.elementTimelineDictionary.ContainsKey(this.Children[this.Children.Count - 1]))
                {
                    DoubleAnimationUsingKeyFrames frames = this.elementTimelineDictionary[this.Children[this.Children.Count - 1]] as DoubleAnimationUsingKeyFrames;
                    if (frames.KeyFrames.Count > 0)
                    {
                        lastRight = frames.KeyFrames[frames.KeyFrames.Count - 1].Value + this.Children[this.Children.Count - 1].DesiredSize.Width;
                    }
                }

                double             firstLeft  = this.SelectedItemLeftMargin;
                TranslateTransform firstTrans = this.Children[0].RenderTransform as TranslateTransform;
                firstLeft = firstTrans.X;

                if (this.elementTimelineDictionary.ContainsKey(this.Children[0]))
                {
                    DoubleAnimationUsingKeyFrames frames = this.elementTimelineDictionary[this.Children[0]] as DoubleAnimationUsingKeyFrames;
                    if (frames.KeyFrames.Count > 0)
                    {
                        firstLeft = frames.KeyFrames[frames.KeyFrames.Count - 1].Value;
                    }
                }

                double startX = lastRight + this.SpaceAfterLastItem;
                double endX   = firstLeft - this.SpaceAfterLastItem;

                if (delta < 0) // forward
                {
                    foreach (UIElement child in this.Children)
                    {
                        trans = child.RenderTransform as TranslateTransform;

                        double fromX = trans.X;
                        Debug.WriteLine(string.Format("Start fromX left {0}", fromX));
                        if (this.elementTimelineDictionary.ContainsKey(child))
                        {
                            DoubleAnimationUsingKeyFrames frames = this.elementTimelineDictionary[child] as DoubleAnimationUsingKeyFrames;
                            fromX = frames.KeyFrames[frames.KeyFrames.Count - 1].Value;

                            Debug.WriteLine(string.Format("End fromX left {0}", fromX));
                        }

                        double toX = fromX + delta;

                        DoubleAnimationUsingKeyFrames doubleAnimationUsingKeyFrames = new DoubleAnimationUsingKeyFrames();
                        doubleAnimationUsingKeyFrames.Duration       = new Duration(animationLength + TimeSpan.FromMilliseconds(index * 10));
                        doubleAnimationUsingKeyFrames.RepeatBehavior = new RepeatBehavior(1);
                        doubleAnimationUsingKeyFrames.AutoReverse    = false;
                        doubleAnimationUsingKeyFrames.FillBehavior   = FillBehavior.HoldEnd;

                        if (child == this.SelectedItem)
                        {
                            doubleAnimationUsingKeyFrames.Completed += new EventHandler(doubleAnimationUsingKeyFrames_Completed);
                        }

                        if (!this.elementTimelineDictionary.ContainsKey(child))
                        {
                            this.elementTimelineDictionary.Add(child, doubleAnimationUsingKeyFrames);
                        }
                        else
                        {
                            this.elementTimelineDictionary[child] = doubleAnimationUsingKeyFrames;
                        }

                        LinearDoubleKeyFrame frame1 = new LinearDoubleKeyFrame();
                        frame1.Value = toX;
                        doubleAnimationUsingKeyFrames.KeyFrames.Add(frame1);

                        if (fromX > lastRight)
                        {
                            startX += child.DesiredSize.Width;
                        }

                        if (toX + child.DesiredSize.Width <= 0) // Move item to end
                        {
                            double fromBK = fromX;
                            if (fromX > lastRight)
                            {
                                startX -= child.DesiredSize.Width;
                            }

                            fromX   = startX;
                            toX     = startX + delta;
                            startX += child.DesiredSize.Width;

                            DiscreteDoubleKeyFrame frame2 = new DiscreteDoubleKeyFrame();
                            frame2.Value = fromX;
                            doubleAnimationUsingKeyFrames.KeyFrames.Add(frame2);

                            LinearDoubleKeyFrame frame3 = new LinearDoubleKeyFrame();
                            frame3.Value = toX;
                            doubleAnimationUsingKeyFrames.KeyFrames.Add(frame3);
                        }

                        if (doubleAnimationUsingKeyFrames.KeyFrames.Count == 3)
                        {
                            doubleAnimationUsingKeyFrames.KeyFrames[0].KeyTime = KeyTime.FromPercent(0.5);
                            doubleAnimationUsingKeyFrames.KeyFrames[1].KeyTime = KeyTime.FromPercent(0.5);
                            doubleAnimationUsingKeyFrames.KeyFrames[2].KeyTime = KeyTime.FromPercent(1.0);
                        }
                        else
                        {
                            doubleAnimationUsingKeyFrames.KeyFrames[0].KeyTime = KeyTime.FromPercent(1.0);
                        }

                        trans.BeginAnimation(TranslateTransform.XProperty,
                                             doubleAnimationUsingKeyFrames,
                                             HandoffBehavior.Compose);
                        trans.BeginAnimation(TranslateTransform.YProperty,
                                             new DoubleAnimation(curY - VerticalOffset, animationLength),
                                             HandoffBehavior.Compose);

                        index++;
                    }
                }
                else
                {
                    index = this.Children.Count;
                    for (int i = this.Children.Count - 1; i >= 0; i--)
                    {
                        UIElement child = this.Children[i];

                        trans = child.RenderTransform as TranslateTransform;

                        double fromX = trans.X;
                        if (this.elementTimelineDictionary.ContainsKey(child))
                        {
                            DoubleAnimationUsingKeyFrames frames = this.elementTimelineDictionary[child] as DoubleAnimationUsingKeyFrames;
                            fromX = frames.KeyFrames[frames.KeyFrames.Count - 1].Value;
                        }

                        double toX = fromX + delta;

                        DoubleAnimationUsingKeyFrames doubleAnimationUsingKeyFrames = new DoubleAnimationUsingKeyFrames();
                        doubleAnimationUsingKeyFrames.Duration       = new Duration(animationLength + TimeSpan.FromMilliseconds(index * 10));
                        doubleAnimationUsingKeyFrames.RepeatBehavior = new RepeatBehavior(1);
                        doubleAnimationUsingKeyFrames.AutoReverse    = false;
                        doubleAnimationUsingKeyFrames.FillBehavior   = FillBehavior.HoldEnd;

                        if (i == this.SelectedIndex)
                        {
                            doubleAnimationUsingKeyFrames.Completed += new EventHandler(doubleAnimationUsingKeyFrames_Completed);
                        }

                        if (!this.elementTimelineDictionary.ContainsKey(child))
                        {
                            this.elementTimelineDictionary.Add(child, doubleAnimationUsingKeyFrames);
                        }
                        else
                        {
                            this.elementTimelineDictionary[child] = doubleAnimationUsingKeyFrames;
                        }

                        LinearDoubleKeyFrame frame1 = new LinearDoubleKeyFrame();
                        frame1.Value = toX;
                        doubleAnimationUsingKeyFrames.KeyFrames.Add(frame1);

                        if (fromX < firstLeft)
                        {
                            endX -= child.DesiredSize.Width;
                        }

                        if (toX > finalSize.Width) // Move item to front
                        {
                            double fromBK = fromX;
                            if (fromX < firstLeft)
                            {
                                endX += child.DesiredSize.Width;
                            }

                            fromX = endX - delta;
                            toX   = endX;
                            endX -= child.DesiredSize.Width;

                            DiscreteDoubleKeyFrame frame2 = new DiscreteDoubleKeyFrame();
                            frame2.Value = fromX;
                            doubleAnimationUsingKeyFrames.KeyFrames.Add(frame2);

                            LinearDoubleKeyFrame frame3 = new LinearDoubleKeyFrame();
                            frame3.Value = toX;
                            doubleAnimationUsingKeyFrames.KeyFrames.Add(frame3);
                        }

                        if (doubleAnimationUsingKeyFrames.KeyFrames.Count == 3)
                        {
                            doubleAnimationUsingKeyFrames.KeyFrames[0].KeyTime = KeyTime.FromPercent(0.5);
                            doubleAnimationUsingKeyFrames.KeyFrames[1].KeyTime = KeyTime.FromPercent(0.5);
                            doubleAnimationUsingKeyFrames.KeyFrames[2].KeyTime = KeyTime.FromPercent(1.0);
                        }
                        else
                        {
                            doubleAnimationUsingKeyFrames.KeyFrames[0].KeyTime = KeyTime.FromPercent(1.0);
                        }

                        trans.BeginAnimation(TranslateTransform.XProperty,
                                             doubleAnimationUsingKeyFrames,
                                             HandoffBehavior.Compose);
                        trans.BeginAnimation(TranslateTransform.YProperty,
                                             new DoubleAnimation(curY - VerticalOffset, animationLength),
                                             HandoffBehavior.Compose);

                        index--;
                    }
                }
            }
            else
            {
                foreach (UIElement child in this.Children)
                {
                    trans = child.RenderTransform as TranslateTransform;

                    double fromX = trans.X;
                    if (this.elementTimelineDictionary.ContainsKey(child))
                    {
                        DoubleAnimation old = this.elementTimelineDictionary[child] as DoubleAnimation;
                        fromX = old.To.Value;
                    }
                    double toX = fromX + delta;

                    DoubleAnimation doubleAnimation = new DoubleAnimation();
                    doubleAnimation.From     = fromX;
                    doubleAnimation.To       = toX;
                    doubleAnimation.Duration = animationLength;

                    trans.BeginAnimation(TranslateTransform.XProperty,
                                         doubleAnimation,
                                         HandoffBehavior.Compose);
                    trans.BeginAnimation(TranslateTransform.YProperty,
                                         new DoubleAnimation(curY - VerticalOffset, animationLength),
                                         HandoffBehavior.Compose);

                    if (!this.elementTimelineDictionary.ContainsKey(child))
                    {
                        this.elementTimelineDictionary.Add(child, doubleAnimation);
                    }
                    else
                    {
                        this.elementTimelineDictionary[child] = doubleAnimation;
                    }

                    index++;
                }
            }

            return(finalSize);
        }