Example #1
0
        public static StoryBoard GetAnimation(ToasterAnimation animation, UIElement toaster)
        {
            var story = new StoryBoard();

            switch (animation)
            {
            case ToasterAnimation.FadeIn:
                DoubleAnimation fadein = new DoubleAnimation(0, 1, TimeSpan.FromSeconds(2))
                {
                    BeginTime = TimeSpan.FromSeconds(0)
                };
                Storyboard.SetTargetProperty(fadein, new PropertyPath("(UIElement.Opacity)"));
                story.Children.Add(fadein);
                DoubleAnimation fadeout = new DoubleAnimation(1, 0, TimeSpan.FromSeconds(2))
                {
                    BeginTime = TimeSpan.FromSeconds(4)
                };
                Storyboard.SetTargetProperty(fadeout, new PropertyPath("(UIElement.Opacity)"));
                story.Children.Add(fadeout);
                break;

            case ToasterAnimation.SlideInFromRight:
                toaster.RenderTransformOrigin = new Point(1, 0);
                toaster.RenderTransform       = new TranslateTransform(300.0, 0);
                var slideinFromRightAnimation = new DoubleAnimationUsingKeyFrames
                {
                    Duration  = new Duration(TimeSpan.FromSeconds(6)),
                    KeyFrames = new DoubleKeyFrameCollection
                    {
                        new EasingDoubleKeyFrame(300.0, KeyTime.FromPercent(0)),
                        new EasingDoubleKeyFrame(0.0, KeyTime.FromPercent(0.1), new ExponentialEase
                        {
                            EasingMode = EasingMode.EaseInOut
                        }),
                        new EasingDoubleKeyFrame(0.0, KeyTime.FromPercent(0.8)),
                        new EasingDoubleKeyFrame(300.0, KeyTime.FromPercent(0.9), new ExponentialEase
                        {
                            EasingMode = EasingMode.EaseOut
                        })
                    }
                };

                Storyboard.SetTargetProperty(slideinFromRightAnimation,
                                             new PropertyPath("RenderTransform.(TranslateTransform.X)"));
                story.Children.Add(slideinFromRightAnimation);
                break;

            case ToasterAnimation.SlideInFromLeft:
                toaster.RenderTransformOrigin = new Point(0, 1);
                toaster.RenderTransform       = new TranslateTransform(-300.0, 0);
                var slideinFromLeftAnimation = new DoubleAnimationUsingKeyFrames
                {
                    Duration  = new Duration(TimeSpan.FromSeconds(6)),
                    KeyFrames = new DoubleKeyFrameCollection
                    {
                        new EasingDoubleKeyFrame(-300.0, KeyTime.FromPercent(0)),
                        new EasingDoubleKeyFrame(0.0, KeyTime.FromPercent(0.1), new ExponentialEase
                        {
                            EasingMode = EasingMode.EaseInOut
                        }),
                        new EasingDoubleKeyFrame(0.0, KeyTime.FromPercent(0.8)),
                        new EasingDoubleKeyFrame(-300.0, KeyTime.FromPercent(0.9), new ExponentialEase
                        {
                            EasingMode = EasingMode.EaseOut
                        })
                    }
                };

                Storyboard.SetTargetProperty(slideinFromLeftAnimation,
                                             new PropertyPath("RenderTransform.(TranslateTransform.X)"));
                story.Children.Add(slideinFromLeftAnimation);
                break;

            case ToasterAnimation.SlideInFromTop:
                toaster.RenderTransformOrigin = new Point(0, 1);
                toaster.RenderTransform       = new TranslateTransform(0, 300);
                var slideinFromTopAnimation = new DoubleAnimationUsingKeyFrames
                {
                    Duration  = new Duration(TimeSpan.FromSeconds(6)),
                    KeyFrames = new DoubleKeyFrameCollection
                    {
                        new EasingDoubleKeyFrame(-300.0, KeyTime.FromPercent(0)),
                        new EasingDoubleKeyFrame(0.0, KeyTime.FromPercent(0.1), new ExponentialEase
                        {
                            EasingMode = EasingMode.EaseInOut
                        }),
                        new EasingDoubleKeyFrame(0.0, KeyTime.FromPercent(0.8)),
                        new EasingDoubleKeyFrame(-300.0, KeyTime.FromPercent(0.9), new ExponentialEase
                        {
                            EasingMode = EasingMode.EaseOut
                        })
                    }
                };

                Storyboard.SetTargetProperty(slideinFromTopAnimation,
                                             new PropertyPath("RenderTransform.(TranslateTransform.Y)"));
                story.Children.Add(slideinFromTopAnimation);
                break;

            case ToasterAnimation.SlideInFromBottom:
                toaster.RenderTransformOrigin = new Point(0, 1);
                toaster.RenderTransform       = new TranslateTransform(0, -300);
                var slideinFromBottomAnimation = new DoubleAnimationUsingKeyFrames
                {
                    Duration  = new Duration(TimeSpan.FromSeconds(6)),
                    KeyFrames = new DoubleKeyFrameCollection
                    {
                        new EasingDoubleKeyFrame(300.0, KeyTime.FromPercent(0)),
                        new EasingDoubleKeyFrame(0.0, KeyTime.FromPercent(0.1), new ExponentialEase
                        {
                            EasingMode = EasingMode.EaseInOut
                        }),
                        new EasingDoubleKeyFrame(0.0, KeyTime.FromPercent(0.8)),
                        new EasingDoubleKeyFrame(300.0, KeyTime.FromPercent(0.9), new ExponentialEase
                        {
                            EasingMode = EasingMode.EaseOut
                        })
                    }
                };

                Storyboard.SetTargetProperty(slideinFromBottomAnimation,
                                             new PropertyPath("RenderTransform.(TranslateTransform.Y)"));
                story.Children.Add(slideinFromBottomAnimation);
                break;

            case ToasterAnimation.GrowFromRight:
                toaster.RenderTransformOrigin = new Point(1, 0);
                DoubleAnimationUsingKeyFrames growfromright = new DoubleAnimationUsingKeyFrames();
                growfromright.KeyFrames.Add(new SplineDoubleKeyFrame(0, TimeSpan.FromSeconds(0)));
                growfromright.KeyFrames.Add(new SplineDoubleKeyFrame(1, TimeSpan.FromSeconds(1.5)));
                growfromright.KeyFrames.Add(new SplineDoubleKeyFrame(1, TimeSpan.FromSeconds(4)));
                growfromright.KeyFrames.Add(new SplineDoubleKeyFrame(0, TimeSpan.FromSeconds(5.5)));
                Storyboard.SetTargetProperty(growfromright,
                                             new PropertyPath("RenderTransform.(ScaleTransform.ScaleX)"));
                story.Children.Add(growfromright);
                break;

            case ToasterAnimation.GrowFromLeft:
                toaster.RenderTransformOrigin = new Point(0, 1);
                DoubleAnimationUsingKeyFrames growfromleft = new DoubleAnimationUsingKeyFrames();
                growfromleft.KeyFrames.Add(new SplineDoubleKeyFrame(0, TimeSpan.FromSeconds(0)));
                growfromleft.KeyFrames.Add(new SplineDoubleKeyFrame(1, TimeSpan.FromSeconds(1.5)));
                growfromleft.KeyFrames.Add(new SplineDoubleKeyFrame(1, TimeSpan.FromSeconds(4)));
                growfromleft.KeyFrames.Add(new SplineDoubleKeyFrame(0, TimeSpan.FromSeconds(5.5)));
                Storyboard.SetTargetProperty(growfromleft,
                                             new PropertyPath("RenderTransform.(ScaleTransform.ScaleX)"));
                story.Children.Add(growfromleft);
                break;

            case ToasterAnimation.GrowFromTop:
                toaster.RenderTransformOrigin = new Point(1, 0);
                DoubleAnimationUsingKeyFrames growfromtop = new DoubleAnimationUsingKeyFrames();
                growfromtop.KeyFrames.Add(new SplineDoubleKeyFrame(0, TimeSpan.FromSeconds(0)));
                growfromtop.KeyFrames.Add(new SplineDoubleKeyFrame(1, TimeSpan.FromSeconds(1.5)));
                growfromtop.KeyFrames.Add(new SplineDoubleKeyFrame(1, TimeSpan.FromSeconds(4)));
                growfromtop.KeyFrames.Add(new SplineDoubleKeyFrame(0, TimeSpan.FromSeconds(5.5)));
                Storyboard.SetTargetProperty(growfromtop,
                                             new PropertyPath("RenderTransform.(ScaleTransform.ScaleY)"));
                story.Children.Add(growfromtop);
                break;

            case ToasterAnimation.GrowFromBottom:
                toaster.RenderTransformOrigin = new Point(0, 1);
                DoubleAnimationUsingKeyFrames growfrombottom = new DoubleAnimationUsingKeyFrames();
                growfrombottom.KeyFrames.Add(new SplineDoubleKeyFrame(0, TimeSpan.FromSeconds(0)));
                growfrombottom.KeyFrames.Add(new SplineDoubleKeyFrame(1, TimeSpan.FromSeconds(1.5)));
                growfrombottom.KeyFrames.Add(new SplineDoubleKeyFrame(1, TimeSpan.FromSeconds(4)));
                growfrombottom.KeyFrames.Add(new SplineDoubleKeyFrame(0, TimeSpan.FromSeconds(5.5)));
                Storyboard.SetTargetProperty(growfrombottom,
                                             new PropertyPath("RenderTransform.(ScaleTransform.ScaleY)"));
                story.Children.Add(growfrombottom);
                break;
            }

            return(story);
        }
        /// <summary>
        /// Blank Constructor
        /// </summary>
        public AnimatedContentControl()
        {
            this.sizeAnimation = new Storyboard();

            DoubleAnimationUsingKeyFrames widthAnimation = new DoubleAnimationUsingKeyFrames();

#if WPF
            // Required for WPF, but causes flickering in Silverlight
            widthAnimation.FillBehavior = FillBehavior.Stop;
#endif
            Storyboard.SetTarget(widthAnimation, this);
            Storyboard.SetTargetProperty(widthAnimation, new System.Windows.PropertyPath("(FrameworkElement.Width)"));
            this.sizeAnimationWidthKeyFrame           = new SplineDoubleKeyFrame();
            this.sizeAnimationWidthKeyFrame.KeySpline = new KeySpline()
            {
                ControlPoint1 = new Point(0.528, 0),
                ControlPoint2 = new Point(0.142, 0.847)
            };
            this.sizeAnimationWidthKeyFrame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(500));
            this.sizeAnimationWidthKeyFrame.Value   = 0;
            widthAnimation.KeyFrames.Add(this.sizeAnimationWidthKeyFrame);

            DoubleAnimationUsingKeyFrames heightAnimation = new DoubleAnimationUsingKeyFrames();

#if WPF
            // Required for WPF, but causes flickering in Silverlight
            heightAnimation.FillBehavior = FillBehavior.Stop;
#endif

            Storyboard.SetTarget(heightAnimation, this);
            Storyboard.SetTargetProperty(heightAnimation, new System.Windows.PropertyPath("(FrameworkElement.Height)"));
            this.sizeAnimationHeightKeyFrame           = new SplineDoubleKeyFrame();
            this.sizeAnimationHeightKeyFrame.KeySpline = new KeySpline()
            {
                ControlPoint1 = new Point(0.528, 0),
                ControlPoint2 = new Point(0.142, 0.847)
            };
            this.sizeAnimationHeightKeyFrame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(500));
            this.sizeAnimationHeightKeyFrame.Value   = 0;
            heightAnimation.KeyFrames.Add(this.sizeAnimationHeightKeyFrame);

            this.sizeAnimation.Children.Add(widthAnimation);
            this.sizeAnimation.Children.Add(heightAnimation);
            this.sizeAnimation.Completed += new EventHandler(this.SizeAnimation_Completed);

            this.positionAnimation = new Storyboard();

            DoubleAnimationUsingKeyFrames positionXAnimation = new DoubleAnimationUsingKeyFrames();

#if WPF
            // Required for WPF, but causes flickering in Silverlight
            positionXAnimation.FillBehavior = FillBehavior.Stop;
#endif

            Storyboard.SetTarget(positionXAnimation, this);
            Storyboard.SetTargetProperty(positionXAnimation, new System.Windows.PropertyPath("(Canvas.Left)"));
            this.positionAnimationXKeyFrame           = new SplineDoubleKeyFrame();
            this.positionAnimationXKeyFrame.KeySpline = new KeySpline()
            {
                ControlPoint1 = new Point(0.528, 0),
                ControlPoint2 = new Point(0.142, 0.847)
            };
            this.positionAnimationXKeyFrame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(500));
            this.positionAnimationXKeyFrame.Value   = 0;
            positionXAnimation.KeyFrames.Add(this.positionAnimationXKeyFrame);

            DoubleAnimationUsingKeyFrames positionYAnimation = new DoubleAnimationUsingKeyFrames();

#if WPF
            // Required for WPF, but causes flickering in Silverlight
            positionYAnimation.FillBehavior = FillBehavior.Stop;
#endif

            Storyboard.SetTarget(positionYAnimation, this);
            Storyboard.SetTargetProperty(positionYAnimation, new System.Windows.PropertyPath("(Canvas.Top)"));
            this.positionAnimationYKeyFrame           = new SplineDoubleKeyFrame();
            this.positionAnimationYKeyFrame.KeySpline = new KeySpline()
            {
                ControlPoint1 = new Point(0.528, 0),
                ControlPoint2 = new Point(0.142, 0.847)
            };
            this.positionAnimationYKeyFrame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(500));
            this.positionAnimationYKeyFrame.Value   = 0;
            positionYAnimation.KeyFrames.Add(this.positionAnimationYKeyFrame);

            this.positionAnimation.Children.Add(positionXAnimation);
            this.positionAnimation.Children.Add(positionYAnimation);

            this.positionAnimation.Completed += new EventHandler(this.PositionAnimation_Completed);
        }
Example #3
0
        private void AddAnimation()
        {
            if (sto == null)
            {
                sto = new Storyboard();
                ThicknessAnimationUsingKeyFrames thicknessAnimation = new ThicknessAnimationUsingKeyFrames();
                thicknessAnimation.AutoReverse    = true;
                thicknessAnimation.RepeatBehavior = RepeatBehavior.Forever;
                thicknessAnimation.KeyFrames      = new ThicknessKeyFrameCollection();

                var keyFrame = new EasingThicknessKeyFrame();
                keyFrame.Value   = new Thickness(1);
                keyFrame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(1));
                thicknessAnimation.KeyFrames.Add(keyFrame);

                Storyboard.SetTarget(thicknessAnimation, border);
                Storyboard.SetTargetProperty(thicknessAnimation, new PropertyPath("BorderThickness"));
                sto.Children.Add(thicknessAnimation);
            }

            if (sto2 == null)
            {
                var b = border2;
                sto2 = (Storyboard)border2.Resources["Storyboard2"];
            }
            if (sto3 == null)
            {
                txt3.RenderTransformOrigin = new Point(0.5, 0.5);
                var tfg = new TransformGroup();
                tfg.Children.Add(new ScaleTransform());
                txt3.RenderTransform = tfg;

                sto3 = new Storyboard();

                DoubleAnimationUsingKeyFrames widthAnimation = new DoubleAnimationUsingKeyFrames();
                widthAnimation.AutoReverse    = true;
                widthAnimation.RepeatBehavior = RepeatBehavior.Forever;
                widthAnimation.KeyFrames      = new DoubleKeyFrameCollection();

                var widthKeyFrame = new EasingDoubleKeyFrame();
                widthKeyFrame.Value   = 1.5;
                widthKeyFrame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(1));
                widthAnimation.KeyFrames.Add(widthKeyFrame);

                Storyboard.SetTarget(widthAnimation, txt3);
                Storyboard.SetTargetProperty(widthAnimation, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)"));

                DoubleAnimationUsingKeyFrames heightAnimation = new DoubleAnimationUsingKeyFrames();
                heightAnimation.AutoReverse    = true;
                heightAnimation.RepeatBehavior = RepeatBehavior.Forever;
                heightAnimation.KeyFrames      = new DoubleKeyFrameCollection();

                var heightKeyFrame = new EasingDoubleKeyFrame();
                heightKeyFrame.Value   = 1.5;
                heightKeyFrame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(1));
                heightAnimation.KeyFrames.Add(heightKeyFrame);

                Storyboard.SetTarget(heightAnimation, txt3);
                Storyboard.SetTargetProperty(heightAnimation, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)"));


                sto3.Children.Add(widthAnimation);
                sto3.Children.Add(heightAnimation);
            }
        }
Example #4
0
        private void AnimateChildrenIn(bool reverse)
        {
            if (_popupContentControl == null)
            {
                return;
            }
            if (VisualTreeHelper.GetChildrenCount(_popupContentControl) != 1)
            {
                return;
            }
            var contentPresenter = VisualTreeHelper.GetChild(_popupContentControl, 0) as ContentPresenter;

            var    controls = contentPresenter.VisualDepthFirstTraversal().OfType <ButtonBase>();
            double translateCoordinateFrom;

            if ((PlacementMode == PopupBoxPlacementMode.TopAndAlignCentres ||
                 PlacementMode == PopupBoxPlacementMode.TopAndAlignLeftEdges ||
                 PlacementMode == PopupBoxPlacementMode.TopAndAlignRightEdges ||
                 PlacementMode == PopupBoxPlacementMode.LeftAndAlignBottomEdges ||
                 PlacementMode == PopupBoxPlacementMode.RightAndAlignBottomEdges ||
                 (UnfurlOrientation == Orientation.Horizontal &&
                  (
                      PlacementMode == PopupBoxPlacementMode.LeftAndAlignBottomEdges ||
                      PlacementMode == PopupBoxPlacementMode.LeftAndAlignMiddles ||
                      PlacementMode == PopupBoxPlacementMode.LeftAndAlignTopEdges
                  ))
                 ))
            {
                controls = controls.Reverse();
                translateCoordinateFrom = 80;
            }
            else
            {
                translateCoordinateFrom = -80;
            }

            var translateCoordinatePath =
                "(UIElement.RenderTransform).(TransformGroup.Children)[1].(TranslateTransform."
                + (UnfurlOrientation == Orientation.Horizontal ? "X)" : "Y)");

            var sineEase = new SineEase();

            var i = 0;

            foreach (var uiElement in controls)
            {
                var deferredStart = i++ *20;
                var deferredEnd   = deferredStart + 200.0;

                var absoluteZeroKeyTime  = KeyTime.FromPercent(0.0);
                var deferredStartKeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(deferredStart));
                var deferredEndKeyTime   = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(deferredEnd));

                var elementTranslateCoordinateFrom = translateCoordinateFrom * i;
                var translateTransform             = new TranslateTransform(
                    UnfurlOrientation == Orientation.Vertical ? 0 : elementTranslateCoordinateFrom,
                    UnfurlOrientation == Orientation.Vertical ? elementTranslateCoordinateFrom : 0);

                var transformGroup = new TransformGroup
                {
                    Children = new TransformCollection(new Transform[]
                    {
                        new ScaleTransform(0, 0),
                        translateTransform
                    })
                };
                uiElement.SetCurrentValue(RenderTransformOriginProperty, new Point(.5, .5));
                uiElement.RenderTransform = transformGroup;

                var opacityAnimation = new DoubleAnimationUsingKeyFrames();
                opacityAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(0, absoluteZeroKeyTime, sineEase));
                opacityAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(0, deferredStartKeyTime, sineEase));
                opacityAnimation.KeyFrames.Add(new EasingDoubleKeyFrame((double)uiElement.GetAnimationBaseValue(OpacityProperty), deferredEndKeyTime, sineEase));
                Storyboard.SetTargetProperty(opacityAnimation, new PropertyPath("Opacity"));
                Storyboard.SetTarget(opacityAnimation, uiElement);

                var scaleXAnimation = new DoubleAnimationUsingKeyFrames();
                scaleXAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(0, absoluteZeroKeyTime, sineEase));
                scaleXAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(0, deferredStartKeyTime, sineEase));
                scaleXAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(1, deferredEndKeyTime, sineEase));
                Storyboard.SetTargetProperty(scaleXAnimation, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)"));
                Storyboard.SetTarget(scaleXAnimation, uiElement);

                var scaleYAnimation = new DoubleAnimationUsingKeyFrames();
                scaleYAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(0, absoluteZeroKeyTime, sineEase));
                scaleYAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(0, deferredStartKeyTime, sineEase));
                scaleYAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(1, deferredEndKeyTime, sineEase));
                Storyboard.SetTargetProperty(scaleYAnimation, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)"));
                Storyboard.SetTarget(scaleYAnimation, uiElement);

                var translateCoordinateAnimation = new DoubleAnimationUsingKeyFrames();
                translateCoordinateAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(elementTranslateCoordinateFrom, absoluteZeroKeyTime, sineEase));
                translateCoordinateAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(elementTranslateCoordinateFrom, deferredStartKeyTime, sineEase));
                translateCoordinateAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(0, deferredEndKeyTime, sineEase));

                Storyboard.SetTargetProperty(translateCoordinateAnimation, new PropertyPath(translateCoordinatePath));
                Storyboard.SetTarget(translateCoordinateAnimation, uiElement);

                var storyboard = new Storyboard();

                storyboard.Children.Add(opacityAnimation);
                storyboard.Children.Add(scaleXAnimation);
                storyboard.Children.Add(scaleYAnimation);
                storyboard.Children.Add(translateCoordinateAnimation);

                if (reverse)
                {
                    storyboard.AutoReverse = true;
                    storyboard.Begin();
                    storyboard.Seek(TimeSpan.FromMilliseconds(deferredEnd));
                    storyboard.Resume();
                }
                else
                {
                    storyboard.Begin();
                }
            }
        }
Example #5
0
        public void Wipe(TransitionerSlide fromSlide, TransitionerSlide toSlide, Point origin, IZIndexController zIndexController)
        {
            if (fromSlide == null)
            {
                throw new ArgumentNullException(nameof(fromSlide));
            }
            if (toSlide == null)
            {
                throw new ArgumentNullException(nameof(toSlide));
            }
            if (zIndexController == null)
            {
                throw new ArgumentNullException(nameof(zIndexController));
            }

            var zeroKeyTime   = KeyTime.FromTimeSpan(TimeSpan.Zero);
            var midishKeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(200));
            var endKeyTime    = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(400));

            //back out old slide setup
            var scaleTransform = new ScaleTransform(1, 1);

            fromSlide.RenderTransform = scaleTransform;
            var scaleAnimation = new DoubleAnimationUsingKeyFrames();

            scaleAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(1, zeroKeyTime));
            scaleAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(.8, endKeyTime));
            scaleAnimation.Completed += (sender, args) =>
            {
                fromSlide.RenderTransform = null;
            };
            var opacityAnimation = new DoubleAnimationUsingKeyFrames();

            opacityAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(1, zeroKeyTime));
            opacityAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(0, endKeyTime));
            opacityAnimation.Completed += (sender, args) =>
            {
                fromSlide.BeginAnimation(UIElement.OpacityProperty, null);
                fromSlide.Opacity = 0;
            };

            //slide in new slide setup
            var translateTransform = new TranslateTransform(0, toSlide.ActualHeight);

            toSlide.RenderTransform = translateTransform;
            var slideAnimation = new DoubleAnimationUsingKeyFrames();

            slideAnimation.KeyFrames.Add(new LinearDoubleKeyFrame(toSlide.ActualHeight, zeroKeyTime));
            slideAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(toSlide.ActualHeight, midishKeyTime)
            {
                EasingFunction = _sineEase
            });
            slideAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(0, endKeyTime)
            {
                EasingFunction = _sineEase
            });

            //kick off!
            translateTransform.BeginAnimation(TranslateTransform.YProperty, slideAnimation);
            scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, scaleAnimation);
            scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, scaleAnimation);
            fromSlide.BeginAnimation(UIElement.OpacityProperty, opacityAnimation);

            zIndexController.Stack(toSlide, fromSlide);
        }
        public static List <Storyboard> GenerateStoryBoards(Canvas canvas, List <List <SketchPoint> > strokes, double pointSize, long pointDuration)
        {
            List <Storyboard> storyboards = new List <Storyboard>();

            long currentTime = 0;

            foreach (List <SketchPoint> points in strokes)
            {
                Storyboard sb = new Storyboard();

                long currStrokeStartTime, currStrokeEndTime;

                currStrokeStartTime = currentTime;

                Ellipse animator = new Ellipse()
                {
                    Width  = pointSize,
                    Height = pointSize,
                    Fill   = new SolidColorBrush(Colors.Green),
                };

                Canvas.SetLeft(animator, -pointSize / 2);
                Canvas.SetTop(animator, -pointSize / 2);
                canvas.Children.Add(animator);

                animator.RenderTransform = new CompositeTransform();

                DoubleAnimationUsingKeyFrames translateXAnimation = new DoubleAnimationUsingKeyFrames();
                DoubleAnimationUsingKeyFrames translateYAnimation = new DoubleAnimationUsingKeyFrames();
                DoubleAnimationUsingKeyFrames fadeAnimation       = new DoubleAnimationUsingKeyFrames();

                for (int i = 0; i < points.Count; i++)
                {
                    KeyTime keyTime             = new TimeSpan(currentTime);
                    EasingDoubleKeyFrame xFrame = new EasingDoubleKeyFrame()
                    {
                        KeyTime = keyTime, Value = points[i].X
                    };
                    EasingDoubleKeyFrame yFrame = new EasingDoubleKeyFrame()
                    {
                        KeyTime = keyTime, Value = points[i].Y
                    };

                    translateXAnimation.KeyFrames.Add(xFrame);
                    translateYAnimation.KeyFrames.Add(yFrame);

                    currentTime += pointDuration;
                }

                currStrokeEndTime = currentTime;

                // fade animations
                fadeAnimation.KeyFrames.Add(new EasingDoubleKeyFrame()
                {
                    KeyTime = new TimeSpan(0), Value = 1
                });
                fadeAnimation.KeyFrames.Add(new EasingDoubleKeyFrame()
                {
                    KeyTime = new TimeSpan(0), Value = 0
                });
                fadeAnimation.KeyFrames.Add(new EasingDoubleKeyFrame()
                {
                    KeyTime = new TimeSpan(currStrokeStartTime), Value = 0
                });
                fadeAnimation.KeyFrames.Add(new EasingDoubleKeyFrame()
                {
                    KeyTime = new TimeSpan(currStrokeStartTime), Value = 1
                });
                fadeAnimation.KeyFrames.Add(new EasingDoubleKeyFrame()
                {
                    KeyTime = new TimeSpan(currStrokeEndTime), Value = 1
                });
                fadeAnimation.KeyFrames.Add(new EasingDoubleKeyFrame()
                {
                    KeyTime = new TimeSpan(currStrokeEndTime), Value = 0
                });

                Storyboard.SetTarget(translateXAnimation, animator);
                Storyboard.SetTarget(translateYAnimation, animator);
                Storyboard.SetTarget(fadeAnimation, animator);

                Storyboard.SetTargetProperty(translateXAnimation, "(UIElement.RenderTransform).(CompositeTransform.TranslateX)");
                Storyboard.SetTargetProperty(translateYAnimation, "(UIElement.RenderTransform).(CompositeTransform.TranslateY)");
                Storyboard.SetTargetProperty(fadeAnimation, "(UIElement.Opacity)");

                sb.Children.Add(translateXAnimation);
                sb.Children.Add(translateYAnimation);
                sb.Children.Add(fadeAnimation);

                storyboards.Add(sb);
            }

            return(storyboards);
        }
Example #7
0
        public override void Begin(Action completionAction)
        {
            Storyboard = new Storyboard();

            double liCounter    = 0;
            var    listBoxItems = ListBox.GetVisualDescendants().OfType <ListBoxItem>().Where(lbi => IsOnCurrentPage(lbi) && lbi.IsEnabled).ToList();

            if (HoldSelectedItem && Direction == Directions.Out && ListBox.SelectedItem != null)
            {
                //move selected container to end
                var selectedContainer = ListBox.ItemContainerGenerator.ContainerFromItem(ListBox.SelectedItem);
                listBoxItems.Remove(selectedContainer);
                listBoxItems.Add(selectedContainer);
            }

            foreach (ListBoxItem li in listBoxItems)
            {
                GeneralTransform gt               = li.TransformToVisual(RootElement);
                Point            globalCoords     = gt.Transform(new Point(0, 0));
                double           heightAdjustment = li.Content is FrameworkElement ? ((li.Content as FrameworkElement).ActualHeight / 2) : (li.ActualHeight / 2);
                //double yCoord = globalCoords.Y + ((((System.Windows.FrameworkElement)(((System.Windows.Controls.ContentControl)(li)).Content)).ActualHeight) / 2);
                double yCoord = globalCoords.Y + heightAdjustment;

                double offsetAmount = (RootElement.ActualHeight / 2) - yCoord;

                PlaneProjection pp = new PlaneProjection();
                pp.GlobalOffsetY     = offsetAmount * -1;
                pp.CenterOfRotationX = 0;
                li.Projection        = pp;

                CompositeTransform ct = new CompositeTransform();
                ct.TranslateY      = offsetAmount;
                li.RenderTransform = ct;

                var beginTime = TimeSpan.FromMilliseconds((FeatherDelay * liCounter) + InitialDelay);

                if (Direction == Directions.In)
                {
                    li.Opacity = 0;

                    DoubleAnimationUsingKeyFrames daukf = new DoubleAnimationUsingKeyFrames();

                    EasingDoubleKeyFrame edkf1 = new EasingDoubleKeyFrame();
                    edkf1.KeyTime = beginTime;
                    edkf1.Value   = Angle;
                    daukf.KeyFrames.Add(edkf1);

                    EasingDoubleKeyFrame edkf2 = new EasingDoubleKeyFrame();
                    edkf2.KeyTime = TimeSpan.FromMilliseconds(Duration).Add(beginTime);
                    edkf2.Value   = 0;

                    ExponentialEase ee = new ExponentialEase();
                    ee.EasingMode = EasingMode.EaseOut;
                    ee.Exponent   = 6;

                    edkf2.EasingFunction = ee;
                    daukf.KeyFrames.Add(edkf2);

                    Storyboard.SetTarget(daukf, li);
                    Storyboard.SetTargetProperty(daukf, new PropertyPath("(UIElement.Projection).(PlaneProjection.RotationY)"));
                    Storyboard.Children.Add(daukf);

                    DoubleAnimation da = new DoubleAnimation();
                    da.Duration  = TimeSpan.FromMilliseconds(0);
                    da.BeginTime = beginTime;
                    da.To        = 1;

                    Storyboard.SetTarget(da, li);
                    Storyboard.SetTargetProperty(da, new PropertyPath("(UIElement.Opacity)"));
                    Storyboard.Children.Add(da);
                }
                else
                {
                    li.Opacity = 1;

                    DoubleAnimation da = new DoubleAnimation();
                    da.BeginTime = beginTime;
                    da.Duration  = TimeSpan.FromMilliseconds(Duration);
                    da.To        = Angle;

                    ExponentialEase ee = new ExponentialEase();
                    ee.EasingMode = EasingMode.EaseIn;
                    ee.Exponent   = 6;

                    da.EasingFunction = ee;

                    Storyboard.SetTarget(da, li);
                    Storyboard.SetTargetProperty(da, new PropertyPath("(UIElement.Projection).(PlaneProjection.RotationY)"));
                    Storyboard.Children.Add(da);

                    da           = new DoubleAnimation();
                    da.Duration  = TimeSpan.FromMilliseconds(10);
                    da.To        = 0;
                    da.BeginTime = TimeSpan.FromMilliseconds(Duration).Add(beginTime);

                    Storyboard.SetTarget(da, li);
                    Storyboard.SetTargetProperty(da, new PropertyPath("(UIElement.Opacity)"));
                    Storyboard.Children.Add(da);
                }

                liCounter++;
            }

            base.Begin(completionAction);
        }
Example #8
0
        public AboutWindow()
        {
            InitializeComponent();
            Storyboard storyboard = new Storyboard();

            canvas.Background = new SolidColorBrush(Color.FromArgb(255, 61, 61, 61));
            for (int index = 0; index < gSpots.Count; index++)
            {
                const int delay        = 30;
                const int duration     = 100;
                const int targetWidth  = 11;
                const int targetHeight = 11;
                const int startWidth   = 0;
                const int startHeight  = 0;
                const int widthOffset  = targetWidth / 2;
                const int heightOffset = targetHeight / 2;
                Point     gSpot        = gSpots[flowOrder[index]];
                Ellipse   ellipse      = new Ellipse();
                ellipse.Width  = startWidth;
                ellipse.Height = startHeight;
                Canvas.SetLeft(ellipse, gSpot.X + widthOffset);
                Canvas.SetTop(ellipse, gSpot.Y + heightOffset);
                ellipse.Fill = new SolidColorBrush(Color.FromRgb(138, 255, 0));
                canvas.Children.Add(ellipse);


                // Width
                DoubleAnimationUsingKeyFrames doubleanimation = new DoubleAnimationUsingKeyFrames();
                doubleanimation.BeginTime = TimeSpan.FromMilliseconds(0 + index * delay);
                SplineDoubleKeyFrame frame = new SplineDoubleKeyFrame(targetWidth, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(duration)));
                doubleanimation.KeyFrames.Add(frame);
                Storyboard.SetTarget(doubleanimation, ellipse);
                Storyboard.SetTargetProperty(doubleanimation, new PropertyPath("(0)", new DependencyProperty[] { Shape.WidthProperty }));
                storyboard.Children.Add(doubleanimation);

                // Height
                doubleanimation           = new DoubleAnimationUsingKeyFrames();
                doubleanimation.BeginTime = TimeSpan.FromMilliseconds(0 + index * delay);
                frame = new SplineDoubleKeyFrame(targetHeight, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(duration)));
                doubleanimation.KeyFrames.Add(frame);
                Storyboard.SetTarget(doubleanimation, ellipse);
                Storyboard.SetTargetProperty(doubleanimation, new PropertyPath("(0)", new DependencyProperty[] { Shape.HeightProperty }));
                storyboard.Children.Add(doubleanimation);

                // Left
                doubleanimation           = new DoubleAnimationUsingKeyFrames();
                doubleanimation.BeginTime = TimeSpan.FromMilliseconds(0 + index * delay);
                frame = new SplineDoubleKeyFrame(gSpot.X, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(duration)));
                doubleanimation.KeyFrames.Add(frame);
                Storyboard.SetTarget(doubleanimation, ellipse);
                Storyboard.SetTargetProperty(doubleanimation, new PropertyPath("(0)", new DependencyProperty[] { Canvas.LeftProperty }));
                storyboard.Children.Add(doubleanimation);

                // Top
                doubleanimation           = new DoubleAnimationUsingKeyFrames();
                doubleanimation.BeginTime = TimeSpan.FromMilliseconds(0 + index * delay);
                frame = new SplineDoubleKeyFrame(gSpot.Y, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(duration)));
                doubleanimation.KeyFrames.Add(frame);
                Storyboard.SetTarget(doubleanimation, ellipse);
                Storyboard.SetTargetProperty(doubleanimation, new PropertyPath("(0)", new DependencyProperty[] { Canvas.TopProperty }));
                storyboard.Children.Add(doubleanimation);
            }
            storyboard.Begin(canvas);
        }
Example #9
0
        private void PlayAnimation()
        {
            double offset = ActualWidth / 3.0;

            double duration = 2.0;
            DoubleAnimationUsingKeyFrames ani = new DoubleAnimationUsingKeyFrames();

            ani.Duration       = TimeSpan.FromSeconds(duration);
            ani.RepeatBehavior = RepeatBehavior.Forever;
            LinearDoubleKeyFrame key = new LinearDoubleKeyFrame();

            key.KeyTime = TimeSpan.FromSeconds(0);
            key.Value   = 0;
            ani.KeyFrames.Add(key);
            key         = new LinearDoubleKeyFrame();
            key.KeyTime = TimeSpan.FromSeconds(duration * 0.2);
            key.Value   = offset;
            ani.KeyFrames.Add(key);
            key         = new LinearDoubleKeyFrame();
            key.KeyTime = TimeSpan.FromSeconds(duration * 0.8);
            key.Value   = offset * 2;
            ani.KeyFrames.Add(key);
            key         = new LinearDoubleKeyFrame();
            key.KeyTime = TimeSpan.FromSeconds(duration);
            key.Value   = offset * 3;
            ani.KeyFrames.Add(key);

            if (Point != null)
            {
                Storyboard storyBoard = new Storyboard();
                storyBoard.BeginTime = TimeSpan.FromSeconds(0);
                Storyboard.SetTarget(ani, Point);
                Storyboard.SetTargetProperty(ani, new PropertyPath("(Canvas.Left)"));
                storyBoard.Children.Add(ani);
                storyBoard.Begin();
            }

            if (Point1 != null)
            {
                Storyboard storyBoard = new Storyboard();
                storyBoard.BeginTime = TimeSpan.FromSeconds(0.1);
                Storyboard.SetTarget(ani, Point1);
                Storyboard.SetTargetProperty(ani, new PropertyPath("(Canvas.Left)"));
                storyBoard.Children.Add(ani);
                storyBoard.Begin();
            }

            if (Point2 != null)
            {
                Storyboard storyBoard = new Storyboard();
                storyBoard.BeginTime = TimeSpan.FromSeconds(0.2);
                Storyboard.SetTarget(ani, Point2);
                Storyboard.SetTargetProperty(ani, new PropertyPath("(Canvas.Left)"));
                storyBoard.Children.Add(ani);
                storyBoard.Begin();
            }

            if (Point3 != null)
            {
                Storyboard storyBoard = new Storyboard();
                storyBoard.BeginTime = TimeSpan.FromSeconds(0.3);
                Storyboard.SetTarget(ani, Point3);
                Storyboard.SetTargetProperty(ani, new PropertyPath("(Canvas.Left)"));
                storyBoard.Children.Add(ani);
                storyBoard.Begin();
            }

            if (Point4 != null)
            {
                Storyboard storyBoard = new Storyboard();
                storyBoard.BeginTime = TimeSpan.FromSeconds(0.4);
                Storyboard.SetTarget(ani, Point4);
                Storyboard.SetTargetProperty(ani, new PropertyPath("(Canvas.Left)"));
                storyBoard.Children.Add(ani);
                storyBoard.Begin();
            }
        }
Example #10
0
        protected override void Init()
        {
            SetBaseView();


            ScaleTransform     translation          = new ScaleTransform(1, 1);
            TranslateTransform translationTranslate = new TranslateTransform(0, 0);

            dauX = new DoubleAnimationUsingKeyFrames();
            dauY = new DoubleAnimationUsingKeyFrames();
            #region 基本工作,确定类型和name
            //是否存在TranslateTransform
            //动画要的类型是否存在
            //动画要的类型的name是否存在,不存在就注册,结束后取消注册,删除动画
            var ex = Element.RenderTransform;
            if (ex == null || (ex as System.Windows.Media.MatrixTransform) != null)
            {
                var tg = new TransformGroup();
                translation = new ScaleTransform(1, 1);

                Win.RegisterName(translation.GetHashCode().ToString(), translation);
                tg.Children.Add(translation);

                Win.RegisterName(translationTranslate.GetHashCode().ToString(), translationTranslate);
                tg.Children.Add(translationTranslate);


                Element.RenderTransform = tg;
            }
            else
            {
                var tg = ex as TransformGroup;
                foreach (var item in tg.Children)
                {
                    translation = item as ScaleTransform;
                    if (translation != null)
                    {
                        break;
                    }
                }

                foreach (var item in tg.Children)
                {
                    translationTranslate = item as TranslateTransform;
                    if (translationTranslate != null)
                    {
                        break;
                    }
                }

                if (translation != null)
                {
                    var tex = translation.GetValue(FrameworkElement.NameProperty);
                    if (tex != null && tex.ToString() != "")
                    {
                    }
                    else
                    {
                        Win.RegisterName(translation.GetHashCode().ToString(), translation);
                    }
                }
                else
                {
                    translation = new ScaleTransform(1, 1);

                    Win.RegisterName(translation.GetHashCode().ToString(), translation);
                    tg.Children.Add(translation);
                    Element.RenderTransform = tg;
                }

                if (translationTranslate != null)
                {
                    var tex = translationTranslate.GetValue(FrameworkElement.NameProperty);
                    if (tex != null && tex.ToString() != "")
                    {
                    }
                    else
                    {
                        Win.RegisterName(translationTranslate.GetHashCode().ToString(), translationTranslate);
                    }
                }
                else
                {
                    translationTranslate = new TranslateTransform(0, 0);
                    Win.RegisterName(translationTranslate.GetHashCode().ToString(), translationTranslate);
                    tg.Children.Add(translationTranslate);
                    Element.RenderTransform = tg;
                }
            }
            #endregion
            Win.RegisterResource(Story);
            Story = (Storyboard)Story.CloneCurrentValue();
            double danqianX = translation.ScaleX;
            double danqianY = translation.ScaleY;


            Element.RenderTransformOrigin = new Point(0, 0.5);
            var keyspline  = new KeySpline(0.55, 0.055, 0.675, 0.19);
            var keyspline2 = new KeySpline(0.175, 0.885, 0.320, 1);

            var k3_0 = new SplineDoubleKeyFrame(1, TimeSpan.FromMilliseconds(AniTime(0)));
            var k3_1 = new SplineDoubleKeyFrame(0.475, TimeSpan.FromMilliseconds(AniTime(0.4)), keyspline2);
            var k3_2 = new SplineDoubleKeyFrame(0.1, TimeSpan.FromMilliseconds(AniTime(1)), keyspline);



            Storyboard.SetTargetName(dauX, Win.GetName(translation));
            Storyboard.SetTargetProperty(dauX, new PropertyPath(ScaleTransform.ScaleXProperty));
            dauX.KeyFrames.Add(k3_0);
            dauX.KeyFrames.Add(k3_1);
            dauX.KeyFrames.Add(k3_2);
            Story.Children.Add(dauX);



            Storyboard.SetTargetName(dauY, Win.GetName(translation));
            Storyboard.SetTargetProperty(dauY, new PropertyPath(ScaleTransform.ScaleYProperty));
            dauY.KeyFrames.Add(k3_0);
            dauY.KeyFrames.Add(k3_1);
            dauY.KeyFrames.Add(k3_2);
            Story.Children.Add(dauY);
            dauX.FillBehavior = FillBehavior.Stop;
            dauY.FillBehavior = FillBehavior.Stop;



            dauTranslateY = new DoubleAnimationUsingKeyFrames();

            var k4_0 = new SplineDoubleKeyFrame(0, TimeSpan.FromMilliseconds(AniTime(0)));
            var k4_1 = new SplineDoubleKeyFrame(42, TimeSpan.FromMilliseconds(AniTime(0.4)), keyspline2);
            var k4_2 = new SplineDoubleKeyFrame(-2000, TimeSpan.FromMilliseconds(AniTime(1)), keyspline);
            dauTranslateY.FillBehavior = FillBehavior.Stop;

            Storyboard.SetTargetName(dauTranslateY, Win.GetName(translationTranslate));
            Storyboard.SetTargetProperty(dauTranslateY, new PropertyPath(TranslateTransform.XProperty));

            dauTranslateY.KeyFrames.Add(k4_0);
            dauTranslateY.KeyFrames.Add(k4_1);
            dauTranslateY.KeyFrames.Add(k4_2);
            Story.Children.Add(dauTranslateY);



            dauOpacty = new DoubleAnimationUsingKeyFrames();
            var k6   = new SplineDoubleKeyFrame(1, TimeSpan.FromMilliseconds(AniTime(0)));
            var k6_1 = new SplineDoubleKeyFrame(1, TimeSpan.FromMilliseconds(AniTime(0.4)), keyspline2);
            var k6_2 = new SplineDoubleKeyFrame(0, TimeSpan.FromMilliseconds(AniTime(1)), keyspline);

            dauOpacty.KeyFrames.Add(k6);
            dauOpacty.KeyFrames.Add(k6_1);
            dauOpacty.KeyFrames.Add(k6_2);
            Storyboard.SetTarget(dauOpacty, Element);
            dauOpacty.FillBehavior = FillBehavior.Stop;
            Storyboard.SetTargetProperty(dauOpacty, new PropertyPath(UIElement.OpacityProperty));
            Story.Children.Add(dauOpacty);

            Story.Completed += Story_Completed;
        }
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            HandPic.Source            = Imaging.CreateBitmapSourceFromHBitmap(HandRes.Hand.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
            _dispatcherTimer.Interval = TimeSpan.FromMilliseconds(_controlInterval);
            _dispatcherTimer.Tick    += Timer_Tick;

            //定义Stoyboard
            DoubleAnimationUsingKeyFrames tempDoubleKeyFrames = new DoubleAnimationUsingKeyFrames();

            tempDoubleKeyFrames.KeyFrames.Add(new EasingDoubleKeyFrame(4, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(0))));
            tempDoubleKeyFrames.KeyFrames.Add(new EasingDoubleKeyFrame(57, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(_controlInterval))));
            Storyboard.SetTargetName(tempDoubleKeyFrames, rectangle.Name);
            Storyboard.SetTargetProperty(tempDoubleKeyFrames, new PropertyPath("(FrameworkElement.Width)"));
            SB_Motion.Children.Add(tempDoubleKeyFrames);

            ThicknessAnimationUsingKeyFrames tempThicknessKeyFrames = new ThicknessAnimationUsingKeyFrames();

            tempThicknessKeyFrames.KeyFrames.Add(new EasingThicknessKeyFrame(new Thickness(28, 28, 0, -28), KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(0))));
            tempThicknessKeyFrames.KeyFrames.Add(new EasingThicknessKeyFrame(new Thickness(1, 1, -59, -38), KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(_controlInterval))));
            Storyboard.SetTargetName(tempThicknessKeyFrames, rectangle.Name);
            Storyboard.SetTargetProperty(tempThicknessKeyFrames, new PropertyPath("(FrameworkElement.Margin)"));
            SB_Motion.Children.Add(tempThicknessKeyFrames);

            //SB_Motion.Children.Add(((Storyboard)FindResource("Motion_Scale")).Children[0]);
            //SB_Motion.Children.Add(((Storyboard)FindResource("Motion_Scale")).Children[1]);

            tempDoubleKeyFrames = new DoubleAnimationUsingKeyFrames();
            tempDoubleKeyFrames.KeyFrames.Add(new EasingDoubleKeyFrame(0, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(0))));
            tempDoubleKeyFrames.KeyFrames.Add(new EasingDoubleKeyFrame(1, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(200))));
            tempDoubleKeyFrames.KeyFrames.Add(new EasingDoubleKeyFrame(1, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(_controlInterval))));
            tempDoubleKeyFrames.KeyFrames.Add(new EasingDoubleKeyFrame(0, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(_controlInterval + 500))));
            Storyboard.SetTargetName(tempDoubleKeyFrames, thCircleLine_Copy.Name);
            Storyboard.SetTargetProperty(tempDoubleKeyFrames, new PropertyPath("(UIElement.Opacity)"));
            SB_Motion.Children.Add(tempDoubleKeyFrames);

            tempDoubleKeyFrames = new DoubleAnimationUsingKeyFrames();
            tempDoubleKeyFrames.KeyFrames.Add(new EasingDoubleKeyFrame(0, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(0))));
            tempDoubleKeyFrames.KeyFrames.Add(new EasingDoubleKeyFrame(_fillOpacity, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(500))));
            tempDoubleKeyFrames.KeyFrames.Add(new EasingDoubleKeyFrame(_fillOpacity, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(_controlInterval))));
            tempDoubleKeyFrames.KeyFrames.Add(new EasingDoubleKeyFrame(0, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(_controlInterval + 500))));
            Storyboard.SetTargetName(tempDoubleKeyFrames, rectangle.Name);
            Storyboard.SetTargetProperty(tempDoubleKeyFrames, new PropertyPath("(UIElement.Opacity)"));
            SB_Motion.Children.Add(tempDoubleKeyFrames);

            tempDoubleKeyFrames = new DoubleAnimationUsingKeyFrames();
            tempDoubleKeyFrames.KeyFrames.Add(new EasingDoubleKeyFrame(_fillOpacity, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(0))));
            tempDoubleKeyFrames.KeyFrames.Add(new EasingDoubleKeyFrame(0, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(500))));
            Storyboard.SetTargetName(tempDoubleKeyFrames, rectangle.Name);
            Storyboard.SetTargetProperty(tempDoubleKeyFrames, new PropertyPath("(UIElement.Opacity)"));
            SB_Stop.Children.Add(tempDoubleKeyFrames);

            tempDoubleKeyFrames = new DoubleAnimationUsingKeyFrames();
            tempDoubleKeyFrames.KeyFrames.Add(new EasingDoubleKeyFrame(1, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(0))));
            tempDoubleKeyFrames.KeyFrames.Add(new EasingDoubleKeyFrame(0, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(500))));
            Storyboard.SetTargetName(tempDoubleKeyFrames, thCircleLine_Copy.Name);
            Storyboard.SetTargetProperty(tempDoubleKeyFrames, new PropertyPath("(UIElement.Opacity)"));
            SB_Stop.Children.Add(tempDoubleKeyFrames);



            //            <Storyboard x:Key="Stop">
            //    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="rectangle">
            //        <EasingDoubleKeyFrame KeyTime="0" Value="0.5"/>
            //        <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="0"/>
            //    </DoubleAnimationUsingKeyFrames>
            //    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="thCircleLine_Copy">
            //        <EasingDoubleKeyFrame KeyTime="0" Value="1"/>
            //        <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="0"/>
            //    </DoubleAnimationUsingKeyFrames>
            //</Storyboard>
        }
Example #12
0
        public override MyAnimateBase Animate()
        {
            IsAnimateCompleted            = false;
            Element.RenderTransformOrigin = new Point(0.5, 0.5);
            Element.Visibility            = Visibility.Visible;
            ScaleTransform translation     = new ScaleTransform(1, 1);
            string         translationName = "";

            Storyboard story = new Storyboard();
            DoubleAnimationUsingKeyFrames dauX = new DoubleAnimationUsingKeyFrames();
            DoubleAnimationUsingKeyFrames dauY = new DoubleAnimationUsingKeyFrames();

            #region 基本工作,确定类型和name
            //是否存在TranslateTransform
            //动画要的类型是否存在
            //动画要的类型的name是否存在,不存在就注册,结束后取消注册,删除动画
            var ex = Element.RenderTransform;
            if (ex == null || (ex as System.Windows.Media.MatrixTransform) != null)
            {
                var tg = new TransformGroup();
                translation     = new ScaleTransform(1, 1);
                translationName = "ayTranslation" + translation.GetHashCode();
                Win.RegisterName(translationName, translation);
                tg.Children.Add(translation);
                Element.RenderTransform = tg;
            }
            else
            {
                var tg = ex as TransformGroup;
                foreach (var item in tg.Children)
                {
                    translation = item as ScaleTransform;
                    if (translation != null)
                    {
                        break;
                    }
                }
                if (translation != null)
                {
                    var tex = translation.GetValue(FrameworkElement.NameProperty);
                    if (tex != null && tex.ToString() != "")
                    {
                        translationName = tex.ToString();
                    }
                    else
                    {
                        translationName = "ayTranslation" + translation.GetHashCode();
                        Win.RegisterName(translationName, translation);
                    }
                }
                else
                {
                    translation     = new ScaleTransform(1, 1);
                    translationName = "ayTranslation" + translation.GetHashCode();
                    Win.RegisterName(translationName, translation);
                    tg.Children.Add(translation);
                    Element.RenderTransform = tg;
                }
            }
            var storyboardName = "aystory" + story.GetHashCode();
            Win.Resources.Add(storyboardName, story);
            double danqianX = translation.ScaleX;
            double danqianY = translation.ScaleY;
            #endregion



            //var k1 = new EasingDoubleKeyFrame(danqianX, TimeSpan.FromMilliseconds(0));
            var k2 = new EasingDoubleKeyFrame(danqianX + 0.3, TimeSpan.FromMilliseconds(AniTime(0.3)));
            var k3 = new EasingDoubleKeyFrame(danqianX, TimeSpan.FromMilliseconds(AniTime(1)), new ElasticEase {
                EasingMode = EasingMode.EaseOut, Oscillations = this.Oscillations
            });
            Storyboard.SetTargetName(dauX, translationName);
            Storyboard.SetTargetProperty(dauX, new PropertyPath(ScaleTransform.ScaleXProperty));

            dauX.KeyFrames.Add(k2);
            dauX.KeyFrames.Add(k3);
            story.Children.Add(dauX);

            var k0 = new EasingDoubleKeyFrame(danqianY - 0.2, TimeSpan.FromMilliseconds(0));
            var k4 = new EasingDoubleKeyFrame(danqianY - 0.2, TimeSpan.FromMilliseconds(AniTime(0.4)));
            var k5 = new EasingDoubleKeyFrame(danqianY, TimeSpan.FromMilliseconds(AniTime(1)), new ElasticEase {
                EasingMode = EasingMode.EaseOut, Oscillations = this.Oscillations
            });
            Storyboard.SetTargetName(dauY, translationName);
            Storyboard.SetTargetProperty(dauY, new PropertyPath(ScaleTransform.ScaleYProperty));
            dauY.KeyFrames.Add(k0);
            dauY.KeyFrames.Add(k4);
            dauY.KeyFrames.Add(k5);
            story.Children.Add(dauY);


            story.Completed +=
                (sndr, evtArgs) =>
            {
                try
                {
                    Win.Resources.Remove(storyboardName);
                    Win.UnregisterName(translationName);

                    dauX.KeyFrames.Clear();
                    dauX = null;
                    dauY.KeyFrames.Clear();
                    dauY  = null;
                    story = null;
                    base.CallClientCompleted();
                }
                catch
                {
                }
            };
            story.Begin(); return(this);
        }
        internal void AnimateContainerDropDown()
        {
            if (Items == null)
            {
                return;
            }
            for (var i = 0; i < Items.Count; i++)
            {
                var container = ContainerFromIndex(i) as FrameworkElement;
                if (container == null)
                {
                    break;
                }

                var itemDropDown  = new Storyboard();
                var quadraticEase = new QuadraticEase {
                    EasingMode = EasingMode.EaseOut
                };
                var initialKeyTime = InitialKeyTime + (KeyTimeStep * i);
                var finalKeyTime   = FinalKeyTime + (KeyTimeStep * i);

                var translation = new TranslateTransform();
                container.RenderTransform = translation;

                var transAnimation = new DoubleAnimationUsingKeyFrames();

                var transKeyFrame1 = new EasingDoubleKeyFrame
                {
                    EasingFunction = quadraticEase,
                    KeyTime        = TimeSpan.FromMilliseconds(0.0),
                    Value          = -150.0
                };

                var transKeyFrame2 = new EasingDoubleKeyFrame
                {
                    EasingFunction = quadraticEase,
                    KeyTime        = TimeSpan.FromMilliseconds(initialKeyTime),
                    Value          = 0.0
                };

                var transKeyFrame3 = new EasingDoubleKeyFrame
                {
                    EasingFunction = quadraticEase,
                    KeyTime        = TimeSpan.FromMilliseconds(finalKeyTime),
                    Value          = 0.0
                };

                transAnimation.KeyFrames.Add(transKeyFrame1);
                transAnimation.KeyFrames.Add(transKeyFrame2);
                transAnimation.KeyFrames.Add(transKeyFrame3);

                Storyboard.SetTarget(transAnimation, container);
                Storyboard.SetTargetProperty(transAnimation, "(UIElement.RenderTransform).(TranslateTransform.Y)");
                itemDropDown.Children.Add(transAnimation);

                var opacityAnimation = new DoubleAnimationUsingKeyFrames();
                var opacityKeyFrame1 = new EasingDoubleKeyFrame
                {
                    EasingFunction = quadraticEase,
                    KeyTime        = TimeSpan.FromMilliseconds(0.0),
                    Value          = 0.0
                };

                var opacityKeyFrame2 = new EasingDoubleKeyFrame
                {
                    EasingFunction = quadraticEase,
                    KeyTime        = TimeSpan.FromMilliseconds(initialKeyTime - 150),
                    Value          = 0.0
                };

                var opacityKeyFrame3 = new EasingDoubleKeyFrame
                {
                    EasingFunction = quadraticEase,
                    KeyTime        = TimeSpan.FromMilliseconds(finalKeyTime),
                    Value          = 1.0
                };

                opacityAnimation.KeyFrames.Add(opacityKeyFrame1);
                opacityAnimation.KeyFrames.Add(opacityKeyFrame2);
                opacityAnimation.KeyFrames.Add(opacityKeyFrame3);

                Storyboard.SetTarget(opacityAnimation, container);
                Storyboard.SetTargetProperty(opacityAnimation, "(UIElement.Opacity)");
                itemDropDown.Children.Add(opacityAnimation);

                itemDropDown.Begin();
            }
        }
Example #14
0
        public AltDoubleAnimationUsingKeyFramesExample()
        {
            Title      = "DoubleAnimationUsingKeyFrames Example";
            Background = Brushes.White;
            Margin     = new Thickness(20);

            // Create a NameScope for this page so that
            // Storyboards can be used.
            NameScope.SetNameScope(this, new NameScope());

            // Create a rectangle.
            Rectangle aRectangle = new Rectangle();

            aRectangle.Width           = 100;
            aRectangle.Height          = 100;
            aRectangle.Stroke          = Brushes.Black;
            aRectangle.StrokeThickness = 5;

            // Create a Canvas to contain and
            // position the rectangle.
            Canvas containerCanvas = new Canvas();

            containerCanvas.Width  = 610;
            containerCanvas.Height = 300;
            containerCanvas.Children.Add(aRectangle);
            Canvas.SetTop(aRectangle, 100);
            Canvas.SetLeft(aRectangle, 10);

            // Create a TranslateTransform to
            // move the rectangle.
            TranslateTransform animatedTranslateTransform =
                new TranslateTransform();

            aRectangle.RenderTransform = animatedTranslateTransform;

            // Assign the TranslateTransform a name so that
            // it can be targeted by a Storyboard.
            this.RegisterName(
                "AnimatedTranslateTransform", animatedTranslateTransform);

            // Create a DoubleAnimationUsingKeyFrames to
            // animate the TranslateTransform.
            DoubleAnimationUsingKeyFrames translationAnimation
                = new DoubleAnimationUsingKeyFrames();

            translationAnimation.Duration = TimeSpan.FromSeconds(6);

            // Animate from the starting position to 500
            // over the first second using linear
            // interpolation.
            translationAnimation.KeyFrames.Add(
                new LinearDoubleKeyFrame(
                    500,                                           // Target value (KeyValue)
                    KeyTime.FromTimeSpan(TimeSpan.FromSeconds(3))) // KeyTime
                );

            // Animate from 500 (the value of the previous key frame)
            // to 400 at 4 seconds using discrete interpolation.
            // Because the interpolation is discrete, the rectangle will appear
            // to "jump" from 500 to 400.
            translationAnimation.KeyFrames.Add(
                new DiscreteDoubleKeyFrame(
                    400,                                           // Target value (KeyValue)
                    KeyTime.FromTimeSpan(TimeSpan.FromSeconds(4))) // KeyTime
                );

            // Animate from 400 (the value of the previous key frame) to 0
            // over two seconds, starting at 4 seconds (the key time of the
            // last key frame) and ending at 6 seconds.
            translationAnimation.KeyFrames.Add(
                new SplineDoubleKeyFrame(
                    0,                                             // Target value (KeyValue)
                    KeyTime.FromTimeSpan(TimeSpan.FromSeconds(6)), // KeyTime
                    new KeySpline(0.6, 0.0, 0.9, 0.0)              // KeySpline
                    )
                );

            // Set the animation to repeat forever.
            translationAnimation.RepeatBehavior = RepeatBehavior.Forever;

            // Set the animation to target the X property
            // of the object named "AnimatedTranslateTransform."
            Storyboard.SetTargetName(translationAnimation, "AnimatedTranslateTransform");
            Storyboard.SetTargetProperty(
                translationAnimation, new PropertyPath(TranslateTransform.XProperty));

            // Create a storyboard to apply the animation.
            Storyboard translationStoryboard = new Storyboard();

            translationStoryboard.Children.Add(translationAnimation);

            // Start the storyboard after the rectangle loads.
            aRectangle.Loaded += delegate(object sender, RoutedEventArgs e)
            {
                translationStoryboard.Begin(this);
            };

            Content = containerCanvas;
        }
        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);
                }
            }
        }
Example #16
0
        private void UpdateIndeterminateAnimation()
        {
            if ((IndeterminateAnimation == null || (IndeterminateAnimation != null && IndeterminateAnimation.Name == DefaultIndeterminateAnimationName)) && Track != null && _arc != null)
            {
                if (IndeterminateAnimation != null && IsIndeterminateAnimationRunning)
                {
                    IsIndeterminateAnimationRunning = false;
                    IndeterminateAnimation.Stop(this);
                    IndeterminateAnimation.Remove(this);
                }

                IndeterminateAnimation = new Storyboard {
                    Name = DefaultIndeterminateAnimationName, RepeatBehavior = RepeatBehavior.Forever
                };

                var trackSize = Math.Min(Track.ActualWidth, Track.ActualHeight);

                var time = Math.Sqrt(trackSize * Math.PI) / Magic;

                var startAngleSetValueAnimation = new DoubleAnimation(Turn * 0, new Duration(TimeSpan.Zero));

                Storyboard.SetTarget(startAngleSetValueAnimation, _arc);
                Storyboard.SetTargetProperty(startAngleSetValueAnimation, new PropertyPath(Arc.StartAngleProperty));

                var endAngleSetValueAnimation = new DoubleAnimation(-Turn * 3 / 4, new Duration(TimeSpan.Zero));

                Storyboard.SetTarget(endAngleSetValueAnimation, _arc);
                Storyboard.SetTargetProperty(endAngleSetValueAnimation, new PropertyPath(Arc.EndAngleProperty));

                var startAngleAnimation = new DoubleAnimationUsingKeyFrames();

                // NOTE: Lack of contracts: DoubleAnimationUsingKeyFrames.KeyFrames is always have collection instance
                Contract.Assume(startAngleAnimation.KeyFrames != null);
                startAngleAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(Turn, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(time))));

                Storyboard.SetTarget(startAngleAnimation, _arc);
                Storyboard.SetTargetProperty(startAngleAnimation, new PropertyPath(Arc.StartAngleProperty));

                var endAngleAnimation = new DoubleAnimationUsingKeyFrames();

                // NOTE: Lack of contracts: DoubleAnimationUsingKeyFrames.KeyFrames is always have collection instance
                Contract.Assume(endAngleAnimation.KeyFrames != null);
                endAngleAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(Turn / 4, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(time))));

                Storyboard.SetTarget(endAngleAnimation, _arc);
                Storyboard.SetTargetProperty(endAngleAnimation, new PropertyPath(Arc.EndAngleProperty));

                // NOTE: Bug in Code Contracts static checker: IndeterminateAnimation can't be null
                // NOTE: Lack of contracts: IndeterminateAnimation.Children is always have collection instance
                Contract.Assume(IndeterminateAnimation != null);
                Contract.Assume(IndeterminateAnimation.Children != null);

                IndeterminateAnimation.Children.Add(startAngleSetValueAnimation);
                IndeterminateAnimation.Children.Add(endAngleSetValueAnimation);
                IndeterminateAnimation.Children.Add(startAngleAnimation);
                IndeterminateAnimation.Children.Add(endAngleAnimation);

                IndeterminateAnimation.Freeze();

                if (State == ProgressState.Indeterminate && IsEnabled)
                {
                    IndeterminateAnimation.Begin(this, Template, true);
                    IsIndeterminateAnimationRunning = true;
                }
            }
        }
Example #17
0
        private DrawingGroup LoadGroup(IList <Shape> elements, Rect?viewBox)
        {
            List <ControlLine> debugPoints = new List <ControlLine>();
            DrawingGroup       grp         = new DrawingGroup();

            if (viewBox.HasValue)
            {
                grp.ClipGeometry = new RectangleGeometry(viewBox.Value);
            }

            foreach (Shape shape in elements)
            {
                if (shape is AnimationBase)
                {
                    if (UseAnimations)
                    {
                        if (shape is AnimateTransform animateTransform)
                        {
                            if (animateTransform.Type == AnimateTransformType.Rotate)
                            {
                                var animation = new DoubleAnimation
                                {
                                    From     = double.Parse(animateTransform.From),
                                    To       = double.Parse(animateTransform.To),
                                    Duration = animateTransform.Duration
                                };
                                animation.RepeatBehavior = RepeatBehavior.Forever;
                                var r = new RotateTransform();
                                grp.Transform = r;
                                r.BeginAnimation(RotateTransform.AngleProperty, animation);
                            }
                        }
                        else if (shape is Animate animate)
                        {
                            var target = this.SVG.GetShape(animate.hRef);
                            var g      = target.geometryElement;
                            //todo : rework this all, generalize it!
                            if (animate.AttributeName == "r")
                            {
                                var animation = new DoubleAnimationUsingKeyFrames()
                                {
                                    Duration = animate.Duration
                                };
                                foreach (var d in animate.Values.Split(';').Select(x => new LinearDoubleKeyFrame(double.Parse(x))))
                                {
                                    animation.KeyFrames.Add(d);
                                }
                                animation.RepeatBehavior = RepeatBehavior.Forever;

                                g.BeginAnimation(EllipseGeometry.RadiusXProperty, animation);
                                g.BeginAnimation(EllipseGeometry.RadiusYProperty, animation);
                            }
                            else if (animate.AttributeName == "cx")
                            {
                                var animation = new PointAnimationUsingKeyFrames()
                                {
                                    Duration = animate.Duration
                                };
                                foreach (var d in animate.Values.Split(';').Select(_ => new LinearPointKeyFrame(new Point(double.Parse(_), ((EllipseGeometry)g).Center.Y))))
                                {
                                    animation.KeyFrames.Add(d);
                                }
                                animation.RepeatBehavior = RepeatBehavior.Forever;
                                g.BeginAnimation(EllipseGeometry.CenterProperty, animation);
                            }
                            else if (animate.AttributeName == "cy")
                            {
                                var animation = new PointAnimationUsingKeyFrames()
                                {
                                    Duration = animate.Duration
                                };
                                foreach (var d in animate.Values.Split(';').Select(_ => new LinearPointKeyFrame(new Point(((EllipseGeometry)g).Center.X, double.Parse(_)))))
                                {
                                    animation.KeyFrames.Add(d);
                                }
                                animation.RepeatBehavior = RepeatBehavior.Forever;
                                g.BeginAnimation(EllipseGeometry.CenterProperty, animation);
                            }
                        }
                    }

                    continue;
                }

                if (shape is UseShape)
                {
                    UseShape useshape = shape as UseShape;
                    Group    group    = this.SVG.GetShape(useshape.hRef) as Group;
                    if (group != null)
                    {
                        Shape oldparent = group.Parent;
                        group.Parent = useshape; // this to get proper style propagated
                        DrawingGroup subgroup = this.LoadGroup(group.Elements, null);
                        if (group.Clip != null)
                        {
                            subgroup.ClipGeometry = group.Clip.ClipGeometry;
                        }
                        subgroup.Transform = new TranslateTransform(useshape.X, useshape.Y);
                        grp.Children.Add(subgroup);
                        group.Parent = oldparent;
                    }
                    continue;
                }
                if (shape is Clip)
                {
                    DrawingGroup subgroup = this.LoadGroup((shape as Clip).Elements, null);
                    if (shape.Transform != null)
                    {
                        subgroup.Transform = shape.Transform;
                    }
                    grp.Children.Add(subgroup);
                    continue;
                }
                if (shape is Group)
                {
                    DrawingGroup subgroup = this.LoadGroup((shape as Group).Elements, null);
                    AddDrawingToGroup(grp, shape, subgroup);
                    continue;
                }
                if (shape is RectangleShape)
                {
                    RectangleShape    r    = shape as RectangleShape;
                    RectangleGeometry rect = new RectangleGeometry(new Rect(r.X, r.Y, r.Width, r.Height));
                    rect.RadiusX = r.RX;
                    rect.RadiusY = r.RY;
                    if (rect.RadiusX == 0 && rect.RadiusY > 0)
                    {
                        rect.RadiusX = rect.RadiusY;
                    }
                    var di = this.NewDrawingItem(shape, rect);
                    AddDrawingToGroup(grp, shape, di);
                }
                if (shape is LineShape)
                {
                    LineShape    r    = shape as LineShape;
                    LineGeometry line = new LineGeometry(r.P1, r.P2);
                    var          di   = this.NewDrawingItem(shape, line);
                    AddDrawingToGroup(grp, shape, di);
                }
                if (shape is PolylineShape)
                {
                    PolylineShape r    = shape as PolylineShape;
                    PathGeometry  path = new PathGeometry();
                    PathFigure    p    = new PathFigure();
                    path.Figures.Add(p);
                    p.IsClosed   = false;
                    p.StartPoint = r.Points[0];
                    for (int index = 1; index < r.Points.Length; index++)
                    {
                        p.Segments.Add(new LineSegment(r.Points[index], true));
                    }
                    var di = this.NewDrawingItem(shape, path);
                    AddDrawingToGroup(grp, shape, di);
                }
                if (shape is PolygonShape)
                {
                    PolygonShape r    = shape as PolygonShape;
                    PathGeometry path = new PathGeometry();
                    PathFigure   p    = new PathFigure();
                    path.Figures.Add(p);
                    p.IsClosed   = true;
                    p.StartPoint = r.Points[0];
                    for (int index = 1; index < r.Points.Length; index++)
                    {
                        p.Segments.Add(new LineSegment(r.Points[index], true));
                    }
                    var di = this.NewDrawingItem(shape, path);
                    AddDrawingToGroup(grp, shape, di);
                }
                if (shape is CircleShape)
                {
                    CircleShape     r  = shape as CircleShape;
                    EllipseGeometry c  = new EllipseGeometry(new Point(r.CX, r.CY), r.R, r.R);
                    var             di = this.NewDrawingItem(shape, c);
                    AddDrawingToGroup(grp, shape, di);
                }
                if (shape is EllipseShape)
                {
                    EllipseShape    r  = shape as EllipseShape;
                    EllipseGeometry c  = new EllipseGeometry(new Point(r.CX, r.CY), r.RX, r.RY);
                    var             di = this.NewDrawingItem(shape, c);
                    AddDrawingToGroup(grp, shape, di);
                }
                if (shape is ImageShape)
                {
                    ImageShape   image = shape as ImageShape;
                    ImageDrawing i     = new ImageDrawing(image.ImageSource, new Rect(image.X, image.Y, image.Width, image.Height));
                    AddDrawingToGroup(grp, shape, i);
                }
                if (shape is TextShape)
                {
                    GeometryGroup gp = TextRender.BuildTextGeometry(shape as TextShape);
                    if (gp != null)
                    {
                        foreach (Geometry gm in gp.Children)
                        {
                            TextShape.TSpan.Element tspan = TextRender.GetElement(gm);
                            if (tspan != null)
                            {
                                var di = this.NewDrawingItem(tspan, gm);
                                AddDrawingToGroup(grp, shape, di);
                            }
                            else
                            {
                                var di = this.NewDrawingItem(shape, gm);
                                AddDrawingToGroup(grp, shape, di);
                            }
                        }
                    }
                }
                if (shape is PathShape)
                {
                    PathShape  r         = shape as PathShape;
                    PathFigure p         = null;
                    Point      lastPoint = new Point(0, 0);

                    PathShape.CurveTo          lastc = null;
                    PathShape.QuadraticCurveTo lastq = null;
                    Point lastcirPoint = new Point(0, 0);

                    PathGeometry path = new PathGeometry();
                    foreach (PathShape.PathElement element in r.Elements)
                    {
                        bool isRelative = element.IsRelative;
                        if (element is PathShape.MoveTo)
                        {
                            p          = new PathFigure();
                            p.IsClosed = r.ClosePath;
                            if (isRelative)
                            {
                                p.StartPoint = lastPoint + (Vector)((PathShape.MoveTo)element).Point;
                            }
                            else
                            {
                                p.StartPoint = ((PathShape.MoveTo)element).Point;
                            }
                            lastPoint = p.StartPoint;
                            path.Figures.Add(p);
                            continue;
                        }
                        if (element is PathShape.LineTo)
                        {
                            PathShape.LineTo lineto = element as PathShape.LineTo;
                            foreach (Point point in lineto.Points)
                            {
                                if (isRelative)
                                {
                                    Point newpoint = lastPoint + (Vector)point;
                                    lastPoint = newpoint;
                                    p.Segments.Add(new LineSegment(newpoint, true));
                                }
                                else
                                {
                                    if (lineto.PositionType == PathShape.LineTo.eType.Point)
                                    {
                                        lastPoint = point;
                                    }
                                    if (lineto.PositionType == PathShape.LineTo.eType.Horizontal)
                                    {
                                        lastPoint = new Point(point.X, lastPoint.Y);
                                    }
                                    if (lineto.PositionType == PathShape.LineTo.eType.Vertical)
                                    {
                                        lastPoint = new Point(lastPoint.X, point.Y);
                                    }
                                    p.Segments.Add(new LineSegment(lastPoint, true));
                                }
                            }
                            continue;
                        }
                        if (element is PathShape.CurveTo)
                        {
                            PathShape.CurveTo c          = element as PathShape.CurveTo;
                            Point             startPoint = lastPoint;
                            BezierSegment     s          = new BezierSegment();
                            if (isRelative)
                            {
                                s.Point1 = lastPoint + (Vector)c.CtrlPoint1;

                                if (c.Command == 's')
                                {
                                    // first control point is a mirrored point of last end control point
                                    //s.Point1 = lastPoint + new Vector(lastc.Point.X - dx, lastc.Point.Y - dy);
                                    //s.Point1 = new Point(lastctrlpoint.X+2, lastctrlpoint.Y+2);

                                    double dx = lastc.CtrlPoint2.X - lastc.Point.X;
                                    double dy = lastc.CtrlPoint2.Y - lastc.Point.Y;
                                    s.Point1 = new Point(lastcirPoint.X - dx, lastcirPoint.Y - dy);
                                    //s.Point1 = lastctrlpoint;
                                }

                                s.Point2 = lastPoint + (Vector)c.CtrlPoint2;
                                s.Point3 = lastPoint + (Vector)c.Point;
                            }
                            else
                            {
                                if (c.Command == 's')
                                {
                                    // first control point is a mirrored point of last end control point
                                    //s.Point1 = lastPoint + new Vector(lastc.Point.X - dx, lastc.Point.Y - dy);
                                    //s.Point1 = new Point(lastctrlpoint.X+2, lastctrlpoint.Y+2);

                                    double dx = lastc.CtrlPoint2.X - lastc.Point.X;
                                    double dy = lastc.CtrlPoint2.Y - lastc.Point.Y;
                                    s.Point1 = new Point(lastcirPoint.X - dx, lastcirPoint.Y - dy);
                                }
                                else
                                {
                                    s.Point1 = c.CtrlPoint1;
                                }
                                s.Point2 = c.CtrlPoint2;
                                s.Point3 = c.Point;
                            }
                            lastPoint = s.Point3;
                            p.Segments.Add(s);

                            lastc        = c;
                            lastcirPoint = s.Point3;

                            //debugPoints.Add(new ControlLine(startPoint, s.Point1));
                            //debugPoints.Add(new ControlLine(s.Point3, s.Point2));
                            continue;
                        }
                        if (element is PathShape.QuadraticCurveTo)
                        {
                            PathShape.QuadraticCurveTo c = element as PathShape.QuadraticCurveTo;
                            Point startPoint             = lastPoint;
                            QuadraticBezierSegment s     = new QuadraticBezierSegment();
                            if (isRelative)
                            {
                                s.Point1 = lastPoint + (Vector)c.CtrlPoint1;

                                if (c.Command == 'q')
                                {
                                    // first control point is a mirrored point of last end control point
                                    //s.Point1 = lastPoint + new Vector(lastc.Point.X - dx, lastc.Point.Y - dy);
                                    //s.Point1 = new Point(lastctrlpoint.X+2, lastctrlpoint.Y+2);

                                    double dx = lastq.CtrlPoint1.X - lastq.Point.X;
                                    double dy = lastq.CtrlPoint1.Y - lastq.Point.Y;
                                    s.Point1 = new Point(lastcirPoint.X - dx, lastcirPoint.Y - dy);
                                    //s.Point1 = lastctrlpoint;
                                }

                                s.Point2 = lastPoint + (Vector)c.Point;
                            }
                            else
                            {
                                if (c.Command == 'q')
                                {
                                    // first control point is a mirrored point of last end control point
                                    //s.Point1 = lastPoint + new Vector(lastc.Point.X - dx, lastc.Point.Y - dy);
                                    //s.Point1 = new Point(lastctrlpoint.X+2, lastctrlpoint.Y+2);

                                    double dx = lastq.CtrlPoint1.X - lastq.Point.X;
                                    double dy = lastq.CtrlPoint1.Y - lastq.Point.Y;
                                    s.Point1 = new Point(lastcirPoint.X - dx, lastcirPoint.Y - dy);
                                }
                                else
                                {
                                    s.Point1 = c.CtrlPoint1;
                                }
                                s.Point2 = c.Point;
                            }
                            lastPoint = s.Point2;
                            p.Segments.Add(s);

                            lastq        = c;
                            lastcirPoint = s.Point2;

                            //debugPoints.Add(new ControlLine(startPoint, s.Point1));
                            //debugPoints.Add(new ControlLine(s.Point3, s.Point2));
                            continue;
                        }
                        if (element is PathShape.EllipticalArcTo)
                        {
                            PathShape.EllipticalArcTo c = element as PathShape.EllipticalArcTo;
                            ArcSegment s = new ArcSegment();
                            if (isRelative)
                            {
                                s.Point = lastPoint + new Vector(c.X, c.Y);
                            }
                            else
                            {
                                s.Point = new Point(c.X, c.Y);
                            }

                            s.Size           = new Size(c.RX, c.RY);
                            s.RotationAngle  = c.AxisRotation;
                            s.SweepDirection = SweepDirection.Counterclockwise;
                            if (c.Clockwise)
                            {
                                s.SweepDirection = SweepDirection.Clockwise;
                            }
                            s.IsLargeArc = c.LargeArc;
                            lastPoint    = s.Point;
                            p.Segments.Add(s);
                            continue;
                        }
                    }

                    /*
                     * if (r.Transform != null)
                     *  path.Transform = r.Transform;
                     */
                    var di = this.NewDrawingItem(shape, path);
                    AddDrawingToGroup(grp, shape, di);
                    //}
                }
            }


            if (debugPoints != null)
            {
                foreach (ControlLine line in debugPoints)
                {
                    grp.Children.Add(line.Draw());
                }
            }
            return(grp);
        }
Example #18
0
        public override MyAnimateBase Animate()
        {
            IsAnimateCompleted            = false;
            Element.RenderTransformOrigin = new Point(0, 0);
            Element.Visibility            = Visibility.Visible;

            RotateTransform    translation          = new RotateTransform();
            TranslateTransform translationTranslate = new TranslateTransform(0, 0);

            string translationName          = "";
            string translationTranslateName = "";

            Storyboard story = new Storyboard();
            DoubleAnimationUsingKeyFrames dau = new DoubleAnimationUsingKeyFrames();

            #region 基本工作,确定类型和name
            //是否存在TranslateTransform
            //动画要的类型是否存在
            //动画要的类型的name是否存在,不存在就注册,结束后取消注册,删除动画
            var ex = Element.RenderTransform;
            if (ex == null || (ex as System.Windows.Media.MatrixTransform) != null)
            {
                var tg = new TransformGroup();
                translation     = new RotateTransform();
                translationName = "ayTranslation" + translation.GetHashCode();
                Win.RegisterName(translationName, translation);
                tg.Children.Add(translation);

                translationTranslateName = "ayTranslation" + translationTranslate.GetHashCode();
                Win.RegisterName(translationTranslateName, translationTranslate);
                tg.Children.Add(translationTranslate);

                Element.RenderTransform = tg;
            }
            else
            {
                var tg = ex as TransformGroup;
                foreach (var item in tg.Children)
                {
                    translation = item as RotateTransform;
                    if (translation != null)
                    {
                        break;
                    }
                }
                foreach (var item in tg.Children)
                {
                    translationTranslate = item as TranslateTransform;
                    if (translationTranslate != null)
                    {
                        break;
                    }
                }

                if (translation != null)
                {
                    var tex = translation.GetValue(FrameworkElement.NameProperty);
                    if (tex != null && tex.ToString() != "")
                    {
                        translationName = tex.ToString();
                    }
                    else
                    {
                        translationName = "ayTranslation" + translation.GetHashCode();
                        Win.RegisterName(translationName, translation);
                    }
                }
                else
                {
                    translation     = new RotateTransform();
                    translationName = "ayTranslation" + translation.GetHashCode();
                    Win.RegisterName(translationName, translation);
                    tg.Children.Add(translation);
                    Element.RenderTransform = tg;
                }

                if (translationTranslate != null)
                {
                    var tex = translationTranslate.GetValue(FrameworkElement.NameProperty);
                    if (tex != null && tex.ToString() != "")
                    {
                        translationTranslateName = tex.ToString();
                    }
                    else
                    {
                        translationTranslateName = "ayTranslation" + translationTranslate.GetHashCode();
                        Win.RegisterName(translationTranslateName, translationTranslate);
                    }
                }
                else
                {
                    translationTranslate     = new TranslateTransform(0, 0);
                    translationTranslateName = "ayTranslation" + translationTranslate.GetHashCode();
                    Win.RegisterName(translationTranslateName, translationTranslate);
                    tg.Children.Add(translationTranslate);
                    Element.RenderTransform = tg;
                }
            }
            #endregion


            var k2   = new EasingDoubleKeyFrame(80, TimeSpan.FromMilliseconds(AniTime(0.2)));
            var k2_2 = new EasingDoubleKeyFrame(40, TimeSpan.FromMilliseconds(AniTime(0.4)));
            var k2_1 = new EasingDoubleKeyFrame(75, TimeSpan.FromMilliseconds(AniTime(0.6)));
            var k2_3 = new EasingDoubleKeyFrame(60, TimeSpan.FromMilliseconds(AniTime(0.8)));
            var k2_4 = new EasingDoubleKeyFrame(0, TimeSpan.FromMilliseconds(AniTime(1)), new CircleEase()
            {
                EasingMode = EasingMode.EaseOut
            });

            Storyboard.SetTargetName(dau, translationName);
            Storyboard.SetTargetProperty(dau, new PropertyPath(RotateTransform.AngleProperty));
            dau.FillBehavior = FillBehavior.Stop;
            var storyboardName = "aystory" + story.GetHashCode();
            Win.Resources.Add(storyboardName, story);

            dau.KeyFrames.Add(k2);
            dau.KeyFrames.Add(k2_1);
            dau.KeyFrames.Add(k2_2);
            dau.KeyFrames.Add(k2_3);
            dau.KeyFrames.Add(k2_4);


            story.Children.Add(dau);



            DoubleAnimationUsingKeyFrames dauTranslateY = new DoubleAnimationUsingKeyFrames();
            var k3   = new EasingDoubleKeyFrame(0, TimeSpan.FromMilliseconds(AniTime(0.8)));
            var k3_1 = new EasingDoubleKeyFrame(700, TimeSpan.FromMilliseconds(AniTime(1)));

            Storyboard.SetTargetName(dauTranslateY, translationTranslateName);
            Storyboard.SetTargetProperty(dauTranslateY, new PropertyPath(TranslateTransform.YProperty));

            dauTranslateY.KeyFrames.Add(k3);
            dauTranslateY.KeyFrames.Add(k3_1);
            story.Children.Add(dauTranslateY);
            dauTranslateY.FillBehavior = FillBehavior.Stop;


            DoubleAnimationUsingKeyFrames dauOpacty = new DoubleAnimationUsingKeyFrames();
            var k4   = new EasingDoubleKeyFrame(1, TimeSpan.FromMilliseconds(AniTime(0.8)));
            var k4_0 = new EasingDoubleKeyFrame(0, TimeSpan.FromMilliseconds(AniTime(1)));

            dauOpacty.KeyFrames.Add(k4);
            dauOpacty.KeyFrames.Add(k4_0);

            Storyboard.SetTarget(dauOpacty, Element);
            dauOpacty.FillBehavior = FillBehavior.Stop;
            Storyboard.SetTargetProperty(dauOpacty, new PropertyPath(UIElement.OpacityProperty));
            story.Children.Add(dauOpacty);


            //PointAnimationUsingKeyFrames porender = new PointAnimationUsingKeyFrames();
            //var k5 = new EasingPointKeyFrame(new Point(0, 0), TimeSpan.FromMilliseconds(0));
            //var k5_0 = new EasingPointKeyFrame(new Point(0, 0), TimeSpan.FromMilliseconds(AniTime(0.8)));
            ////var k5_1 = new EasingPointKeyFrame(new Point(0.4, 0.9), TimeSpan.FromMilliseconds(AniTime(0.8001)));
            //porender.KeyFrames.Add(k5);
            //porender.KeyFrames.Add(k5_0);
            ////porender.KeyFrames.Add(k5_1);

            //Storyboard.SetTarget(porender, Element);
            //dauOpacty.FillBehavior = FillBehavior.Stop;
            //Storyboard.SetTargetProperty(porender, new PropertyPath(UIElement.RenderTransformOriginProperty));
            //story.Children.Add(porender);

            story.Completed +=
                (sndr, evtArgs) =>
            {
                try
                {
                    Element.Visibility = Visibility.Collapsed;

                    Win.Resources.Remove(storyboardName);
                    Win.UnregisterName(translationName);
                    Win.UnregisterName(translationTranslateName);

                    dau.KeyFrames.Clear();
                    dauTranslateY.KeyFrames.Clear();

                    dauTranslateY = null;
                    dau           = null;
                    story         = null;

                    base.CallClientCompleted();
                }
                catch
                {
                }
            };
            story.Begin(); return(this);
        }
Example #19
0
        /// <summary>
        /// Walks through the known storyboards in the control's template that
        /// may contain identifying values, storing them for future
        /// use and updates.
        /// </summary>
        private void UpdateAnyAnimationValues()
        {
            if (_knownHeight > 0 && _knownWidth > 0)
            {
                // Initially, before any special animations have been found,
                // the visual state groups of the control must be explored.
                // By definition they must be at the implementation root of the
                // control.
                if (_specialAnimations == null)
                {
                    _specialAnimations = new List <AnimationValueAdapter>();

                    foreach (VisualStateGroup group in VisualStateManager.GetVisualStateGroups(this))
                    {
                        if (group == null)
                        {
                            continue;
                        }
                        foreach (VisualState state in group.States)
                        {
                            if (state != null)
                            {
                                Storyboard sb = state.Storyboard;

                                if (sb != null)
                                {
                                    // Examine all children of the storyboards,
                                    // looking for either type of double
                                    // animation.
                                    foreach (Timeline timeline in sb.Children)
                                    {
                                        DoubleAnimation da = timeline as DoubleAnimation;
                                        DoubleAnimationUsingKeyFrames dakeys = timeline as DoubleAnimationUsingKeyFrames;
                                        if (da != null)
                                        {
                                            ProcessDoubleAnimation(da);
                                        }
                                        else if (dakeys != null)
                                        {
                                            ProcessDoubleAnimationWithKeys(dakeys);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                // Update special animation values relative to the current size.
                UpdateKnownAnimations();

                // HACK: force storyboard to use new values
                foreach (VisualStateGroup group in VisualStateManager.GetVisualStateGroups(this))
                {
                    if (group == null)
                    {
                        continue;
                    }
                    foreach (VisualState state in group.States)
                    {
                        if (state != null)
                        {
                            Storyboard sb = state.Storyboard;

                            if (sb != null)
                            {
                                // need to kick the storyboard, otherwise new values are not taken into account.
                                // it's sad, really don't want to start storyboards in vsm, but I see no other option
                                sb.Begin(this);
                            }
                        }
                    }
                }
            }
        }
        public void Wipe(TransitionerSlide fromSlide, TransitionerSlide toSlide, Point origin, IZIndexController zIndexController)
        {
            if (fromSlide == null)
            {
                throw new ArgumentNullException(nameof(fromSlide));
            }
            if (toSlide == null)
            {
                throw new ArgumentNullException(nameof(toSlide));
            }
            if (zIndexController == null)
            {
                throw new ArgumentNullException(nameof(zIndexController));
            }

            var horizontalProportion = Math.Max(1.0 - origin.X, 1.0 * origin.X);
            var verticalProportion   = Math.Max(1.0 - origin.Y, 1.0 * origin.Y);
            var radius = Math.Sqrt(Math.Pow(toSlide.ActualWidth * horizontalProportion, 2) + Math.Pow(toSlide.ActualHeight * verticalProportion, 2));

            var scaleTransform     = new ScaleTransform(0, 0);
            var translateTransform = new TranslateTransform(toSlide.ActualWidth * origin.X, toSlide.ActualHeight * origin.Y);
            var transformGroup     = new TransformGroup();

            transformGroup.Children.Add(scaleTransform);
            transformGroup.Children.Add(translateTransform);
            var ellipseGeomotry = new EllipseGeometry()
            {
                RadiusX   = radius,
                RadiusY   = radius,
                Transform = transformGroup
            };

            toSlide.SetCurrentValue(UIElement.ClipProperty, ellipseGeomotry);
            zIndexController.Stack(toSlide, fromSlide);

            var zeroKeyTime = KeyTime.FromTimeSpan(TimeSpan.Zero);
            var midKeyTime  = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(200));
            var endKeyTime  = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(400));

            var opacityAnimation = new DoubleAnimationUsingKeyFrames();

            opacityAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(1, zeroKeyTime));
            opacityAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(1, midKeyTime));
            opacityAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(0, endKeyTime));
            opacityAnimation.Completed += (sender, args) =>
            {
                fromSlide.BeginAnimation(UIElement.OpacityProperty, null);
                fromSlide.Opacity = 0;
            };
            fromSlide.BeginAnimation(UIElement.OpacityProperty, opacityAnimation);

            var scaleAnimation = new DoubleAnimationUsingKeyFrames();

            scaleAnimation.Completed += (sender, args) =>
            {
                toSlide.SetCurrentValue(UIElement.ClipProperty, null);
                fromSlide.BeginAnimation(UIElement.OpacityProperty, null);
                fromSlide.Opacity = 0;
            };
            scaleAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(0, zeroKeyTime));
            scaleAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(1, endKeyTime));
            scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, scaleAnimation);
            scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, scaleAnimation);
        }
Example #21
0
        public override MyAnimateBase Animate()
        {
            IsAnimateCompleted            = false;
            Element.RenderTransformOrigin = new Point(0.5, 0.5);
            Element.Visibility            = Visibility.Visible;

            TranslateTransform translation     = new TranslateTransform(0, 0);
            string             translationName = "";

            Storyboard story = new Storyboard();
            DoubleAnimationUsingKeyFrames dau = new DoubleAnimationUsingKeyFrames();

            #region 基本工作,确定类型和name
            //是否存在TranslateTransform
            //动画要的类型是否存在
            //动画要的类型的name是否存在,不存在就注册,结束后取消注册,删除动画
            var ex = Element.RenderTransform;
            if (ex == null || (ex as System.Windows.Media.MatrixTransform) != null)
            {
                var tg = new TransformGroup();
                translation     = new TranslateTransform(0, 0);
                translationName = "ayTranslation" + translation.GetHashCode();
                Win.RegisterName(translationName, translation);
                tg.Children.Add(translation);
                Element.RenderTransform = tg;
            }
            else
            {
                var tg = ex as TransformGroup;
                foreach (var item in tg.Children)
                {
                    translation = item as TranslateTransform;
                    if (translation != null)
                    {
                        break;
                    }
                }
                if (translation != null)
                {
                    //当前Y值
                    var tex = translation.GetValue(FrameworkElement.NameProperty);
                    if (tex != null && tex.ToString() != "")
                    {
                        translationName = tex.ToString();
                    }
                    else
                    {
                        translationName = "ayTranslation" + translation.GetHashCode();
                        Win.RegisterName(translationName, translation);
                    }
                }
                else
                {
                    translation     = new TranslateTransform(0, 0);
                    translationName = "ayTranslation" + translation.GetHashCode();
                    Win.RegisterName(translationName, translation);
                    tg.Children.Add(translation);
                    Element.RenderTransform = tg;
                }
            }
            #endregion
            double danqianY = translation.Y;
            //var k1 = new EasingDoubleKeyFrame(danqianY, TimeSpan.FromMilliseconds(0));
            var k2 = new EasingDoubleKeyFrame((danqianY - UpHeight), TimeSpan.FromMilliseconds(AniTime(0.2)), new PowerEase {
                EasingMode = EasingMode.EaseOut
            });
            var k3 = new EasingDoubleKeyFrame(danqianY, TimeSpan.FromMilliseconds(AniTime(1)), new BounceEase {
                EasingMode = EasingMode.EaseOut, Bounces = this.Bounces, Bounciness = this.Bounciness
            });

            Storyboard.SetTargetName(dau, translationName);
            Storyboard.SetTargetProperty(dau, new PropertyPath(TranslateTransform.YProperty));

            var storyboardName = "aystory" + story.GetHashCode();
            Win.Resources.Add(storyboardName, story);

            //dau.KeyFrames.Add(k1);
            dau.KeyFrames.Add(k2);
            dau.KeyFrames.Add(k3);

            story.Children.Add(dau);

            story.Completed +=
                (sndr, evtArgs) =>
            {
                try
                {
                    Win.Resources.Remove(storyboardName);
                    Win.UnregisterName(translationName);

                    dau.KeyFrames.Clear();
                    dau   = null;
                    story = null;
                    base.CallClientCompleted();
                }
                catch
                {
                }
            };
            story.Begin(); return(this);
        }
Example #22
0
        private static void Show(Popup popup, Action complete = null, double height = 60, double life = 3)
        {
            try
            {
                if (!(popup.Child.RenderTransform is CompositeTransform))
                {
                    popup.Child.RenderTransform = new CompositeTransform();
                }
                ((CompositeTransform)popup.Child.RenderTransform).TranslateY = -height;

                Debug.Assert(popup.Child is FrameworkElement);

                var element = popup.Child as FrameworkElement;
                element.Height = height;

                var storyboard = new Storyboard
                {
                    AutoReverse = false
                };

                var doubleAnimaionUsingKeyFrames = new DoubleAnimationUsingKeyFrames();
                Storyboard.SetTarget(doubleAnimaionUsingKeyFrames, popup.Child);
                Storyboard.SetTargetProperty(doubleAnimaionUsingKeyFrames, "(UIElement.Opacity)");
                storyboard.Children.Add(doubleAnimaionUsingKeyFrames);

                //0.5秒透明度从0-1
                var doubleKeyFrame = new EasingDoubleKeyFrame
                {
                    KeyTime        = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.5)),
                    Value          = 1,
                    EasingFunction = new CubicEase {
                        EasingMode = EasingMode.EaseOut
                    }
                };
                doubleAnimaionUsingKeyFrames.KeyFrames.Add(doubleKeyFrame);
                doubleKeyFrame = new EasingDoubleKeyFrame
                {
                    KeyTime        = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(2.4)),
                    Value          = 0.995,
                    EasingFunction = new CubicEase {
                        EasingMode = EasingMode.EaseIn
                    }
                };
                doubleAnimaionUsingKeyFrames.KeyFrames.Add(doubleKeyFrame);
                doubleKeyFrame = new EasingDoubleKeyFrame
                {
                    KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(3)),
                    Value   = 0.1,
                };
                doubleAnimaionUsingKeyFrames.KeyFrames.Add(doubleKeyFrame);



                doubleAnimaionUsingKeyFrames = new DoubleAnimationUsingKeyFrames();
                Storyboard.SetTarget(doubleAnimaionUsingKeyFrames, popup.Child);
                Storyboard.SetTargetProperty(doubleAnimaionUsingKeyFrames,
                                             "(UIElement.RenderTransform).(CompositeTransform.TranslateY)");
                storyboard.Children.Add(doubleAnimaionUsingKeyFrames);
                doubleKeyFrame = new EasingDoubleKeyFrame
                {
                    KeyTime        = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.5)),
                    Value          = 0,
                    EasingFunction = new CubicEase {
                        EasingMode = EasingMode.EaseOut
                    }
                };
                doubleAnimaionUsingKeyFrames.KeyFrames.Add(doubleKeyFrame);
                doubleKeyFrame = new EasingDoubleKeyFrame
                {
                    KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(2.4)),
                    Value   = 0,
                };
                doubleAnimaionUsingKeyFrames.KeyFrames.Add(doubleKeyFrame);
                doubleKeyFrame = new EasingDoubleKeyFrame
                {
                    KeyTime        = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(life)),
                    Value          = -height,
                    EasingFunction = new CubicEase {
                        EasingMode = EasingMode.EaseIn
                    }
                };
                doubleAnimaionUsingKeyFrames.KeyFrames.Add(doubleKeyFrame);

                var objectAnimaionUsingKeyFrames = new ObjectAnimationUsingKeyFrames();
                Storyboard.SetTarget(objectAnimaionUsingKeyFrames, popup);
                Storyboard.SetTargetProperty(objectAnimaionUsingKeyFrames, "(Popup.IsOpen)");
                storyboard.Children.Add(objectAnimaionUsingKeyFrames);

                var discreteObjectKeyFrame = new DiscreteObjectKeyFrame
                {
                    KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)),
                    Value   = true
                };
                objectAnimaionUsingKeyFrames.KeyFrames.Add(discreteObjectKeyFrame);

                discreteObjectKeyFrame = new DiscreteObjectKeyFrame
                {
                    KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(life)),
                    Value   = false
                };
                objectAnimaionUsingKeyFrames.KeyFrames.Add(discreteObjectKeyFrame);

                if (complete != null)
                {
                    storyboard.Completed += (s, e) => complete.Invoke();
                }

                storyboard.Begin();
            }
            catch
            {
            }
        }
        protected override void Init()
        {
            SetBaseView();
            SkewTransform translation = new SkewTransform(0, 0);

            dauX = new DoubleAnimationUsingKeyFrames();
            dauY = new DoubleAnimationUsingKeyFrames();
            #region 基本工作,确定类型和name
            //是否存在TranslateTransform
            //动画要的类型是否存在
            //动画要的类型的name是否存在,不存在就注册,结束后取消注册,删除动画
            var ex = Element.RenderTransform;
            if (ex == null || (ex as System.Windows.Media.MatrixTransform) != null)
            {
                var tg = new TransformGroup();
                translation = new SkewTransform(1, 1);
                Win.RegisterName(translation.GetHashCode().ToString(), translation);
                tg.Children.Add(translation);
                Element.RenderTransform = tg;
            }
            else
            {
                var tg = ex as TransformGroup;
                foreach (var item in tg.Children)
                {
                    translation = item as SkewTransform;
                    if (translation != null)
                    {
                        break;
                    }
                }
                if (translation != null)
                {
                    var tex = translation.GetValue(FrameworkElement.NameProperty);
                    if (tex != null && tex.ToString() != "")
                    {
                    }
                    else
                    {
                        Win.RegisterName(translation.GetHashCode().ToString(), translation);
                    }
                }
                else
                {
                    translation = new SkewTransform(0, 0);
                    Win.RegisterName(translation.GetHashCode().ToString(), translation);
                    tg.Children.Add(translation);
                    Element.RenderTransform = tg;
                }
            }
            #endregion

            Win.RegisterResource(Story);
            double danqianX = translation.AngleX;
            double danqianY = translation.AngleY;


            var k2   = new EasingDoubleKeyFrame(danqianX - 12.5, TimeSpan.FromMilliseconds(AniTime(0.222)));
            var k2_0 = new EasingDoubleKeyFrame(danqianX + 6.25, TimeSpan.FromMilliseconds(AniTime(0.333)));
            var k2_1 = new EasingDoubleKeyFrame(danqianX - 3.125, TimeSpan.FromMilliseconds(AniTime(0.444)));
            var k2_2 = new EasingDoubleKeyFrame(danqianX + 1.5625, TimeSpan.FromMilliseconds(AniTime(0.555)));
            var k2_3 = new EasingDoubleKeyFrame(danqianX - 0.78125, TimeSpan.FromMilliseconds(AniTime(0.666)));
            var k2_4 = new EasingDoubleKeyFrame(danqianX + 0.390625, TimeSpan.FromMilliseconds(AniTime(0.777)));
            var k2_5 = new EasingDoubleKeyFrame(danqianX - 0.1953125, TimeSpan.FromMilliseconds(AniTime(0.888)));
            var k2_6 = new EasingDoubleKeyFrame(danqianX, TimeSpan.FromMilliseconds(AniTime(1)));

            var k3   = new EasingDoubleKeyFrame(danqianY - 12.5, TimeSpan.FromMilliseconds(AniTime(0.222)));
            var k3_0 = new EasingDoubleKeyFrame(danqianY + 6.25, TimeSpan.FromMilliseconds(AniTime(0.333)));
            var k3_1 = new EasingDoubleKeyFrame(danqianY - 3.125, TimeSpan.FromMilliseconds(AniTime(0.444)));
            var k3_2 = new EasingDoubleKeyFrame(danqianY + 1.5625, TimeSpan.FromMilliseconds(AniTime(0.555)));
            var k3_3 = new EasingDoubleKeyFrame(danqianY - 0.78125, TimeSpan.FromMilliseconds(AniTime(0.666)));
            var k3_4 = new EasingDoubleKeyFrame(danqianY + 0.390625, TimeSpan.FromMilliseconds(AniTime(0.777)));
            var k3_5 = new EasingDoubleKeyFrame(danqianY - 0.1953125, TimeSpan.FromMilliseconds(AniTime(0.888)));
            var k3_6 = new EasingDoubleKeyFrame(danqianY, TimeSpan.FromMilliseconds(AniTime(1)));



            Storyboard.SetTargetName(dauX, Win.GetName(translation));
            Storyboard.SetTargetProperty(dauX, new PropertyPath(SkewTransform.AngleXProperty));
            dauX.KeyFrames.Add(k2);
            dauX.KeyFrames.Add(k2_0);
            dauX.KeyFrames.Add(k2_1);
            dauX.KeyFrames.Add(k2_2);
            dauX.KeyFrames.Add(k2_3);
            dauX.KeyFrames.Add(k2_4);
            dauX.KeyFrames.Add(k2_5);
            dauX.KeyFrames.Add(k2_6);
            Story = (Storyboard)Story.CloneCurrentValue();
            Story.Children.Add(dauX);


            Storyboard.SetTargetName(dauY, Win.GetName(translation));
            Storyboard.SetTargetProperty(dauY, new PropertyPath(SkewTransform.AngleYProperty));
            dauY.KeyFrames.Add(k3);
            dauY.KeyFrames.Add(k3_0);
            dauY.KeyFrames.Add(k3_1);
            dauY.KeyFrames.Add(k3_2);
            dauY.KeyFrames.Add(k3_3);
            dauY.KeyFrames.Add(k3_4);
            dauY.KeyFrames.Add(k3_5);
            dauY.KeyFrames.Add(k3_6);
            Story.Children.Add(dauY);


            Story.Completed -= Story_Completed;
            Story.Completed += Story_Completed;
        }
        /// <summary> 执行方法 </summary>
        protected override void Invoke(object parameter)
        {
            if (this.AssociatedObject == null)
            {
                return;
            }

            if (this.AutoFindParent)
            {
                this.Target = this.AssociatedObject.GetParent <Panel>();
            }

            if (this.Target == null)
            {
                this.Target = this.AssociatedObject;
            }

            IEnumerable <UIElement> children = null;

            if (IsUseAll)
            {
                children = this.Target.GetChildren <UIElement>().Where(l => l.RenderTransform is TransformGroup);

                children = children.Where(l => (l.RenderTransform as TransformGroup).Children.Count == 4);

                children = children.Where(l => (l as FrameworkElement)?.Tag?.ToString() != "Except" && !InvokeRandomSplitAnimationAction.GetIsExcept(l));
            }
            else
            {
                if (this.Target is Panel panel)
                {
                    children = panel.Children?.Cast <UIElement>()?.Where(l => l.RenderTransform is TransformGroup);

                    children = children.Where(l => (l.RenderTransform as TransformGroup).Children.Count == 4 && !InvokeRandomSplitAnimationAction.GetIsExcept(l));
                }
            }

            if (children == null)
            {
                return;
            }

            var controls = children?.ToList();

            if (controls == null || controls.Count == 0)
            {
                return;
            }

            if (this.UseIndex)
            {
                controls = this.RandomList(controls);
            }

            Storyboard storyboard = new Storyboard();

            for (int i = 0; i < controls.Count; i++)
            {
                if (this.UseOrigin)
                {
                    controls[i].RenderTransformOrigin = this.GetRandomOrigin();
                }

                foreach (var item in Timelines.OfType <RandomDoubleAnimation>())
                {
                    TimeSpan span = TimeSpan.FromMilliseconds(i * (SplitMilliSecond + item.Duration.TimeSpan.TotalMilliseconds));

                    TimeSpan end = item.Duration.TimeSpan + span;

                    DoubleAnimation animation = item.ConvertTo();

                    if (item.BeginTime == TimeSpan.Zero)
                    {
                        DoubleAnimationUsingKeyFrames frames = new DoubleAnimationUsingKeyFrames();

                        EasingDoubleKeyFrame key1 = new EasingDoubleKeyFrame(animation.From.Value, KeyTime.FromTimeSpan(TimeSpan.Zero));

                        frames.KeyFrames.Add(key1);
                        Storyboard.SetTarget(frames, controls[i]);
                        Storyboard.SetTargetProperty(frames, Storyboard.GetTargetProperty(item));
                        storyboard.Children.Add(frames);
                    }


                    animation.BeginTime = span + animation.BeginTime;
                    Storyboard.SetTarget(animation, controls[i]);

                    storyboard.Children.Add(animation);
                }

                foreach (var item in Timelines.OfType <ThicknessAnimation>())
                {
                    TimeSpan span = TimeSpan.FromMilliseconds(i * (SplitMilliSecond + item.Duration.TimeSpan.TotalMilliseconds));

                    TimeSpan end = item.Duration.TimeSpan + span;

                    ThicknessAnimationUsingKeyFrames frames = new ThicknessAnimationUsingKeyFrames();

                    EasingThicknessKeyFrame key1 = new EasingThicknessKeyFrame(item.From.Value, KeyTime.FromTimeSpan(TimeSpan.Zero));

                    frames.KeyFrames.Add(key1);
                    Storyboard.SetTarget(frames, controls[i]);
                    Storyboard.SetTargetProperty(frames, Storyboard.GetTargetProperty(item));
                    storyboard.Children.Add(frames);

                    ThicknessAnimation animation = item.Clone();
                    animation.BeginTime = span;
                    Storyboard.SetTarget(animation, controls[i]);

                    storyboard.Children.Add(animation);
                }
            }

            storyboard.FillBehavior = FillBehavior.HoldEnd;

            storyboard.RepeatBehavior = this.RepeatBehavior;

            storyboard.Begin();
        }
        private void Trace(Canvas canvas, List <InkStroke> strokesCollection, List <List <long> > timesCollection, bool hasTime)
        {
            if (hasTime)
            {
                // offset and shift the times
                // that is, offset all the times so that the first time is zeroed
                // and shift the times so that the delay between each stroke is one second
                List <List <long> > originalTimesCollection = timesCollection;
                timesCollection = new List <List <long> >();
                long shift  = 0;
                long offset = myTimeCollection[0][0];
                for (int i = 0; i < myTimeCollection.Count; ++i)
                {
                    // begin shifting after the first stroke
                    if (i > 0)
                    {
                        long previousLastTime = myTimeCollection[i - 1][myTimeCollection[i - 1].Count - 1];
                        long currentFirstTime = myTimeCollection[i][0];
                        shift += currentFirstTime - previousLastTime - 1000000;
                    }

                    // include the shift and offset values
                    List <long> times = new List <long>();
                    for (int j = 0; j < myTimeCollection[i].Count; ++j)
                    {
                        long time = myTimeCollection[i][j] - shift - offset;
                        times.Add(time);
                    }
                    timesCollection.Add(times);
                }
            }

            // iterate through each stroke
            for (int i = 0; i < strokesCollection.Count; ++i)
            {
                // get the current stroke and times
                InkStroke   stroke      = strokesCollection[i];
                List <long> times       = timesCollection[i];
                int         pointsCount = stroke.GetInkPoints().Count;
                int         count       = pointsCount < times.Count ? pointsCount : times.Count;

                // get the tracer's starting position
                double startX = stroke.GetInkPoints()[0].Position.X;
                double startY = stroke.GetInkPoints()[0].Position.Y;

                // create the stroke's corresponding tracer
                Ellipse tracer = new Ellipse()
                {
                    Width  = 30,
                    Height = 30,
                    Fill   = new SolidColorBrush(Colors.Red)
                };

                // add the tracer to the canvas
                // note: the tracer is moved up and left its radius to center
                Canvas.SetLeft(tracer, -tracer.Width / 2);
                Canvas.SetTop(tracer, -tracer.Height / 2);
                canvas.Children.Add(tracer);

                // initialize the storyboard and animations
                tracer.RenderTransform = new CompositeTransform();
                Storyboard storyboard = new Storyboard();
                DoubleAnimationUsingKeyFrames translateXAnimation = new DoubleAnimationUsingKeyFrames();
                DoubleAnimationUsingKeyFrames translateYAnimation = new DoubleAnimationUsingKeyFrames();
                DoubleAnimationUsingKeyFrames fadeAnimation       = new DoubleAnimationUsingKeyFrames();

                // create the tracer's translation animations
                KeyTime keyTime;
                EasingDoubleKeyFrame frameX, frameY;
                double x, y;
                for (int j = 0; j < count; ++j)
                {
                    keyTime = new TimeSpan(times[j]);
                    x       = stroke.GetInkPoints()[j].Position.X;
                    y       = stroke.GetInkPoints()[j].Position.Y;

                    frameX = new EasingDoubleKeyFrame()
                    {
                        KeyTime = keyTime, Value = x
                    };
                    frameY = new EasingDoubleKeyFrame()
                    {
                        KeyTime = keyTime, Value = y
                    };

                    translateXAnimation.KeyFrames.Add(frameX);
                    translateYAnimation.KeyFrames.Add(frameY);
                }

                // create the tracer's fade animations
                long firstTime = times[0];
                long lastTime  = times[times.Count - 1];
                fadeAnimation.KeyFrames.Add(new EasingDoubleKeyFrame()
                {
                    KeyTime = new TimeSpan(0), Value = 1
                });
                fadeAnimation.KeyFrames.Add(new EasingDoubleKeyFrame()
                {
                    KeyTime = new TimeSpan(0), Value = 0
                });
                fadeAnimation.KeyFrames.Add(new EasingDoubleKeyFrame()
                {
                    KeyTime = new TimeSpan(firstTime), Value = 0
                });
                fadeAnimation.KeyFrames.Add(new EasingDoubleKeyFrame()
                {
                    KeyTime = new TimeSpan(firstTime), Value = 1
                });
                fadeAnimation.KeyFrames.Add(new EasingDoubleKeyFrame()
                {
                    KeyTime = new TimeSpan(lastTime), Value = 1
                });
                fadeAnimation.KeyFrames.Add(new EasingDoubleKeyFrame()
                {
                    KeyTime = new TimeSpan(lastTime), Value = 0
                });

                // assign the animations to the tracer
                Storyboard.SetTarget(translateXAnimation, tracer);
                Storyboard.SetTarget(translateYAnimation, tracer);
                Storyboard.SetTarget(fadeAnimation, tracer);

                // assign the animations to their behavior's properties
                Storyboard.SetTargetProperty(translateXAnimation, "(UIElement.RenderTransform).(CompositeTransform.TranslateX)");
                Storyboard.SetTargetProperty(translateYAnimation, "(UIElement.RenderTransform).(CompositeTransform.TranslateY)");
                Storyboard.SetTargetProperty(fadeAnimation, "(UIElement.Opacity)");

                // add the animations to the storyboard
                storyboard.Children.Add(translateXAnimation);
                storyboard.Children.Add(translateYAnimation);
                storyboard.Children.Add(fadeAnimation);

                // begin the storyboard
                storyboard.Begin();
            }
        }
Example #26
0
        private void MainItemGrid_OnTap(object sender, GestureEventArgs e)
        {
            if (ViewModel.IsWorking)
            {
                return;
            }

            var frameworkElement = sender as FrameworkElement;

            if (frameworkElement == null)
            {
                return;
            }

            var user = frameworkElement.DataContext as TLUserBase;

            if (user == null)
            {
                return;
            }

            ViewModel.UserAction(user);

            var tapedItem = frameworkElement;

            _tapedItem = tapedItem;

            VisualTreeExtensions.FindVisualChildWithPredicate <TextBlock>(tapedItem, AnimatedBasePage.GetIsAnimationTarget);

            if (!(_tapedItem.RenderTransform is CompositeTransform))
            {
                _tapedItem.RenderTransform = new CompositeTransform();
            }

            FrameworkElement tapedItemContainer = _tapedItem.FindParentOfType <ListBoxItem>();

            if (tapedItemContainer != null)
            {
                tapedItemContainer = tapedItemContainer.FindParentOfType <ContentPresenter>();
            }

            var storyboard = new Storyboard();

            var timeline = new DoubleAnimationUsingKeyFrames();

            timeline.KeyFrames.Add(new EasingDoubleKeyFrame {
                KeyTime = TimeSpan.FromSeconds(0.0), Value = 0.0
            });
            timeline.KeyFrames.Add(new EasingDoubleKeyFrame {
                KeyTime = TimeSpan.FromSeconds(0.25), Value = 73.0
            });
            Storyboard.SetTarget(timeline, tapedItem);
            Storyboard.SetTargetProperty(timeline, new PropertyPath("(UIElement.RenderTransform).(CompositeTransform.TranslateY)"));
            storyboard.Children.Add(timeline);

            var timeline2 = new DoubleAnimationUsingKeyFrames();

            timeline2.KeyFrames.Add(new EasingDoubleKeyFrame {
                KeyTime = TimeSpan.FromSeconds(0.0), Value = 0.0
            });
            timeline2.KeyFrames.Add(new EasingDoubleKeyFrame {
                KeyTime = TimeSpan.FromSeconds(0.25), Value = 425.0, EasingFunction = new ExponentialEase {
                    EasingMode = EasingMode.EaseIn, Exponent = 5.0
                }
            });
            Storyboard.SetTarget(timeline2, tapedItem);
            Storyboard.SetTargetProperty(timeline2, new PropertyPath("(UIElement.RenderTransform).(CompositeTransform.TranslateX)"));
            storyboard.Children.Add(timeline2);

            var timeline3 = new DoubleAnimationUsingKeyFrames();

            timeline3.KeyFrames.Add(new EasingDoubleKeyFrame {
                KeyTime = TimeSpan.FromSeconds(0.0), Value = 1.0
            });
            timeline3.KeyFrames.Add(new EasingDoubleKeyFrame {
                KeyTime = TimeSpan.FromSeconds(0.2), Value = 1.0
            });
            timeline3.KeyFrames.Add(new EasingDoubleKeyFrame {
                KeyTime = TimeSpan.FromSeconds(0.25), Value = 0.0
            });
            Storyboard.SetTarget(timeline3, tapedItem);
            Storyboard.SetTargetProperty(timeline3, new PropertyPath("(UIElement.Opacity)"));
            storyboard.Children.Add(timeline3);

            if (tapedItemContainer != null)
            {
                var timeline4 = new ObjectAnimationUsingKeyFrames();
                timeline4.KeyFrames.Add(new DiscreteObjectKeyFrame {
                    KeyTime = TimeSpan.FromSeconds(0.0), Value = 999.0
                });
                timeline4.KeyFrames.Add(new DiscreteObjectKeyFrame {
                    KeyTime = TimeSpan.FromSeconds(0.25), Value = 0.0
                });
                Storyboard.SetTarget(timeline4, tapedItemContainer);
                Storyboard.SetTargetProperty(timeline4, new PropertyPath("(Canvas.ZIndex)"));
                storyboard.Children.Add(timeline4);
            }
            _lastStoryboard = storyboard;
            storyboard.Begin();
        }
Example #27
0
 public static void SetStoryBoardTarget(DoubleAnimationUsingKeyFrames animation, string targetName)
 {
     animation.SetValue(Storyboard.TargetNameProperty, targetName);
 }
Example #28
0
        /// <summary>
        /// Walks through the known storyboards in the control's template that
        /// may contain identifying values, storing them for future
        /// use and updates.
        /// </summary>
        void UpdateAnyAnimationValues()
        {
            if (_knownHeight > 0 && _knownWidth > 0)
            {
                // Initially, before any special animations have been found,
                // the visual state groups of the control must be explored.
                // By definition they must be at the implementation root of the
                // control.
                if (_specialAnimations == null)
                {
                    _specialAnimations = new List <AnimationValueAdapter>();

                    foreach (VisualStateGroup group in VisualStateManager.GetVisualStateGroups(this))
                    {
                        if (group == null)
                        {
                            continue;
                        }
                        foreach (VisualState state in group.States)
                        {
                            if (state != null)
                            {
                                Storyboard sb = state.Storyboard;

                                if (sb != null)
                                {
                                    // Examine all children of the storyboards,
                                    // looking for either type of double
                                    // animation.
                                    foreach (Timeline timeline in sb.Children)
                                    {
                                        DoubleAnimation da = timeline as DoubleAnimation;
                                        DoubleAnimationUsingKeyFrames dakeys = timeline as DoubleAnimationUsingKeyFrames;
                                        if (da != null)
                                        {
                                            // Look for a special value in the To property.
                                            if (da.To.HasValue)
                                            {
                                                var d = DoubleAnimationToAdapter.GetDimensionFromIdentifyingValue(da.To.Value);
                                                if (d.HasValue)
                                                {
                                                    _specialAnimations.Add(new DoubleAnimationToAdapter(d.Value, da));
                                                }
                                            }

                                            // Look for a special value in the From property.
                                            if (da.From.HasValue)
                                            {
                                                var d = DoubleAnimationFromAdapter.GetDimensionFromIdentifyingValue(da.To.Value);
                                                if (d.HasValue)
                                                {
                                                    _specialAnimations.Add(new DoubleAnimationFromAdapter(d.Value, da));
                                                }
                                            }
                                        }
                                        else if (dakeys != null)
                                        {
                                            // Look through all keyframes in the instance.
                                            foreach (DoubleKeyFrame frame in dakeys.KeyFrames)
                                            {
                                                var d = DoubleAnimationFrameAdapter.GetDimensionFromIdentifyingValue(frame.Value);
                                                if (d.HasValue)
                                                {
                                                    _specialAnimations.Add(new DoubleAnimationFrameAdapter(d.Value, frame));
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                // Update special animation values relative to the current size.
                foreach (AnimationValueAdapter adapter in _specialAnimations)
                {
                    adapter.UpdateWithNewDimension(_knownWidth, _knownHeight);
                }

                // HACK: force storyboard to use new values
                foreach (VisualStateGroup group in VisualStateManager.GetVisualStateGroups(this))
                {
                    if (group == null)
                    {
                        continue;
                    }
                    foreach (VisualState state in group.States)
                    {
                        if (state != null)
                        {
                            Storyboard sb = state.Storyboard;

                            if (sb != null)
                            {
                                // need to kick the storyboard, otherwise new values are not taken into account.
                                // it's sad, really don't want to start storyboards in vsm, but I see no other option
                                sb.Begin(this);
                            }
                        }
                    }
                }
            }
        }
Example #29
0
        void AssociatedObject_Drawed(object sender, RoutedEventArgs e)
        {
            var items = this.GetChildren <UIElement>().Where(l => l.RenderTransform is TransformGroup);

            items = items.Where(l => (l.RenderTransform as TransformGroup).Children.Count == 4);

            var controls = items?.ToList();

            if (controls == null || controls.Count == 0)
            {
                return;
            }

            Storyboard storyboard = new Storyboard();

            for (int i = 0; i < controls.Count; i++)
            {
                foreach (var item in Timelines.OfType <DoubleAnimation>())
                {
                    TimeSpan span = TimeSpan.FromMilliseconds(i * (SplitMilliSecond + item.Duration.TimeSpan.TotalMilliseconds));

                    TimeSpan end = item.Duration.TimeSpan + span;

                    DoubleAnimationUsingKeyFrames frames = new DoubleAnimationUsingKeyFrames();

                    EasingDoubleKeyFrame key1 = new EasingDoubleKeyFrame(item.From.Value, KeyTime.FromTimeSpan(TimeSpan.Zero));

                    frames.KeyFrames.Add(key1);
                    Storyboard.SetTarget(frames, controls[i]);
                    Storyboard.SetTargetProperty(frames, Storyboard.GetTargetProperty(item));
                    storyboard.Children.Add(frames);

                    DoubleAnimation animation = item.Clone();
                    animation.BeginTime = span;
                    Storyboard.SetTarget(animation, controls[i]);

                    storyboard.Children.Add(animation);
                }

                foreach (var item in Timelines.OfType <ThicknessAnimation>())
                {
                    TimeSpan span = TimeSpan.FromMilliseconds(i * (SplitMilliSecond + item.Duration.TimeSpan.TotalMilliseconds));

                    TimeSpan end = item.Duration.TimeSpan + span;

                    ThicknessAnimationUsingKeyFrames frames = new ThicknessAnimationUsingKeyFrames();

                    EasingThicknessKeyFrame key1 = new EasingThicknessKeyFrame(item.From.Value, KeyTime.FromTimeSpan(TimeSpan.Zero));

                    frames.KeyFrames.Add(key1);
                    Storyboard.SetTarget(frames, controls[i]);
                    Storyboard.SetTargetProperty(frames, Storyboard.GetTargetProperty(item));
                    storyboard.Children.Add(frames);

                    ThicknessAnimation animation = item.Clone();
                    animation.BeginTime = span;
                    Storyboard.SetTarget(animation, controls[i]);

                    storyboard.Children.Add(animation);
                }
            }

            storyboard.FillBehavior = FillBehavior.HoldEnd;
            storyboard.Begin();
        }
Example #30
0
   public static Timeline CreateKeyFrameAnimation(this Storyboard storyboard, IList<double> values, 
 IList<Duration> times)
   {
       var keyFrameAnimation = new DoubleAnimationUsingKeyFrames();
         var keyTime = TimeSpan.FromMilliseconds(0);
         for (var i = 0; i < values.Count(); i++)
         {
       keyTime += times[i].TimeSpan;
       var frame = new LinearDoubleKeyFrame { Value = values[i], KeyTime = keyTime };
       keyFrameAnimation.KeyFrames.Add(frame);
       keyFrameAnimation.Duration += times[i];
         }
         return keyFrameAnimation;
   }
Example #31
0
 public LoadingPage(string Username, string Password)
 {
     this.InitializeComponent();
     //settitlecolor();
     Loaded += async delegate
     {
         //Perform the animations
         BindableMargin margin = new Views.BindableMargin(image);
         DoubleAnimationUsingKeyFrames animation = new DoubleAnimationUsingKeyFrames();
         animation.EnableDependentAnimation = true;
         EasingDoubleKeyFrame f1 = new EasingDoubleKeyFrame();
         f1.Value   = 0;
         f1.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.2));
         animation.KeyFrames.Add(f1);
         EasingDoubleKeyFrame f2 = new EasingDoubleKeyFrame();
         f2.EasingFunction = new PowerEase()
         {
             EasingMode = EasingMode.EaseInOut, Power = 4
         };
         f2.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.8));
         f2.Value   = -Window.Current.Bounds.Height / 4;
         animation.KeyFrames.Add(f2);
         Storyboard.SetTarget(animation, margin);
         Storyboard.SetTargetProperty(animation, "Top");
         //DoubleAnimation animation2 = new DoubleAnimation();
         //Storyboard.SetTarget(animation2, image);
         //Storyboard.SetTargetProperty(animation2, "Opacity");
         //animation2.Duration = new Duration(TimeSpan.FromSeconds(1));
         //animation2.From = 0;
         //animation2.To = 100;
         //Windows Phones do not need the animation
         //if (DeviceTypeHelper.GetDeviceFormFactorType() != DeviceFormFactorType.Phone)
         {
             storyboard.Children.Add(animation);
             //storyboard.Children.Add(animation2);
         }
         //Only phones should have this step
         if (ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar"))
         {
             //var appview = ApplicationView.GetForCurrentView();
             //appview.SetDesiredBoundsMode(ApplicationViewBoundsMode.UseCoreWindow);
             var statusbar = Windows.UI.ViewManagement.StatusBar.GetForCurrentView();
             statusbar.ForegroundColor   = Colors.White;
             statusbar.BackgroundOpacity = 0;
             await statusbar.HideAsync();
         }
         storyboard.Completed += delegate
         {
             //Main animation finish
             BindableMargin margin2 = new Views.BindableMargin(image);
             image.Opacity = 100;
             margin2.Top   = -Window.Current.Bounds.Height / 4;
             ring.IsActive = true;
             BeginLoading(Username, Password);
         };
         storyboard.Begin();
     };
     SizeChanged += delegate
     {
         if (!isLoaded)
         {
             isLoaded = true;
             return;
         }
         BindableMargin margin = new Views.BindableMargin(image);
         storyboard.Stop();
         image.Opacity = 100;
         margin.Top    = -Window.Current.Bounds.Height / 4;
     };
 }