public static Storyboard CreateDoubleSB(DependencyObject dpnObj, string property, double secondTime, Double from, Double to, EasingMode em)
        {
        //<Storyboard x:Name="Storyboard1">
        //    <DoubleAnimationUsingKeyFrames EnableDependentAnimation="True" Storyboard.TargetProperty="(FrameworkElement.Height)" Storyboard.TargetName="border">
        //        <EasingDoubleKeyFrame KeyTime="0:0:1" Value="0"/>
        //    </DoubleAnimationUsingKeyFrames>
        //</Storyboard>
            DoubleAnimationUsingKeyFrames daKeyFrame = new DoubleAnimationUsingKeyFrames();
            EasingDoubleKeyFrame edKeyFrame = new EasingDoubleKeyFrame();
            edKeyFrame.KeyTime = TimeSpan.FromSeconds(secondTime);
            edKeyFrame.Value = to;
            CircleEase ce = new CircleEase();
            ce.EasingMode = em;
            edKeyFrame.EasingFunction = ce;

            daKeyFrame.KeyFrames.Add(edKeyFrame);
            daKeyFrame.EnableDependentAnimation = true;

            Storyboard.SetTarget(daKeyFrame, dpnObj);
            Storyboard.SetTargetProperty(daKeyFrame, property);
            Storyboard sb = new Storyboard();

            sb.Children.Add(daKeyFrame);
            return sb;
        }
        public static Storyboard CreateSizeAnimation(
            this Storyboard sb,
            FrameworkElement target,
            Size start,
            Size end,
            double timeSecs = 1.0,
            double delay = 0)
        {
            if (sb == null)
                throw new NullReferenceException("The storyboard could not be Null");

            DoubleAnimationUsingKeyFrames animH = new DoubleAnimationUsingKeyFrames();
            DoubleAnimationUsingKeyFrames animW = new DoubleAnimationUsingKeyFrames();
            EasingDoubleKeyFrame d1;
            EasingDoubleKeyFrame d2;

            //Creating Hight Frames
            d1 = new EasingDoubleKeyFrame();
            d1.Value = start.Height;
            d1.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(delay));

            d2 = new EasingDoubleKeyFrame();
            d2.Value = end.Height;
            d2.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(delay+timeSecs));

            animH.KeyFrames.Add(d1);
            animH.KeyFrames.Add(d2);
            animH.EnableDependentAnimation = true;
            //////////////////////////////////////

            //Creating Width Frames
            d1 = new EasingDoubleKeyFrame();
            d1.Value = start.Width;
            d1.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(delay));

            d2 = new EasingDoubleKeyFrame();
            d2.Value = end.Width;
            d2.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(delay+timeSecs));


            animW.KeyFrames.Add(d1);
            animW.KeyFrames.Add(d2);
            animW.EnableDependentAnimation = true;

            //////////////////////////////////////

            sb.Children.Add(animH);
            sb.Children.Add(animW);

            Storyboard.SetTarget(animH, target);
            Storyboard.SetTarget(animW, target);
            Storyboard.SetTargetProperty(animH, "(FrameworkElement.Height)");
            Storyboard.SetTargetProperty(animW, "(FrameworkElement.Width)");

            sb.SetStoryboardDuration(new Duration(TimeSpan.FromSeconds(delay + timeSecs)));

            return sb;
        }
Exemple #3
0
        public static void Appear(FrameworkElement el, int millisecondPostpone = 0)
        {
            if (el.GetType().Name == "SplashScreenView")
            {
                el.Opacity =1.0;
                return;
            }


            DispatchedHandler invokedHandler = new DispatchedHandler(() =>
            {
                TranslateTransform translateTransform = new TranslateTransform();
                el.RenderTransform = translateTransform;
                translateTransform.X = (double)Animation.pixelsMove;
                if (translateTransform != null)
                {
                    SplineDoubleKeyFrame splineDoubleKeyFrame = new SplineDoubleKeyFrame();
                    splineDoubleKeyFrame.KeyTime = TimeSpan.FromMilliseconds((double)(10 + millisecondPostpone));
                    splineDoubleKeyFrame.Value = (double)Animation.pixelsMove;
                    SplineDoubleKeyFrame splineDoubleKeyFrame2 = new SplineDoubleKeyFrame();
                    splineDoubleKeyFrame2.KeyTime = TimeSpan.FromMilliseconds((double)(350 + millisecondPostpone));
                    splineDoubleKeyFrame2.Value = 0.0;
                    splineDoubleKeyFrame2.KeySpline = new KeySpline();
                    splineDoubleKeyFrame2.KeySpline.ControlPoint1 = new Point(0.0, 0.0);
                    splineDoubleKeyFrame2.KeySpline.ControlPoint2 = new Point(0.0, 1.0);
                    DoubleAnimationUsingKeyFrames doubleAnimationUsingKeyFrames = new DoubleAnimationUsingKeyFrames();
                    Storyboard.SetTarget(doubleAnimationUsingKeyFrames, translateTransform);
                    Storyboard.SetTargetProperty(doubleAnimationUsingKeyFrames, "(TranslateTransform.X)");
                    doubleAnimationUsingKeyFrames.KeyFrames.Add(splineDoubleKeyFrame);
                    doubleAnimationUsingKeyFrames.KeyFrames.Add(splineDoubleKeyFrame2);
                    SplineDoubleKeyFrame splineDoubleKeyFrame3 = new SplineDoubleKeyFrame();
                    splineDoubleKeyFrame3.KeyTime = TimeSpan.FromMilliseconds((double)millisecondPostpone);
                    splineDoubleKeyFrame3.Value = 0.0;
                    SplineDoubleKeyFrame splineDoubleKeyFrame4 = new SplineDoubleKeyFrame();
                    splineDoubleKeyFrame4.KeyTime = TimeSpan.FromMilliseconds((double)(300 + millisecondPostpone));
                    splineDoubleKeyFrame4.Value = 1.0;
                    DoubleAnimationUsingKeyFrames doubleAnimationUsingKeyFrames2 = new DoubleAnimationUsingKeyFrames();
                    Storyboard.SetTarget(doubleAnimationUsingKeyFrames2, el);
                    Storyboard.SetTargetProperty(doubleAnimationUsingKeyFrames2, "(UIElement.Opacity)");
                    doubleAnimationUsingKeyFrames2.KeyFrames.Add(splineDoubleKeyFrame3);
                    doubleAnimationUsingKeyFrames2.KeyFrames.Add(splineDoubleKeyFrame4);
                    Storyboard storyboard = new Storyboard();
                    storyboard.Children.Add(doubleAnimationUsingKeyFrames);
                    storyboard.Children.Add(doubleAnimationUsingKeyFrames2);
                    storyboard.Begin();
                }

            });


            el.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, invokedHandler).GetResults();
        }
Exemple #4
0
        private void Init()
        {
            _Storyboard = new Storyboard();
            _Storyboard.Completed += _Storyboard_Completed;

            /***animation x***/
            _Animation_X = new DoubleAnimationUsingKeyFrames();

            /*key frame x from*/
            _KeyFrame_x_from = new EasingDoubleKeyFrame();
            _KeyFrame_x_from.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0));
            _KeyFrame_x_from.Value = 0;
            _Animation_X.KeyFrames.Add(_KeyFrame_x_from);

            /*key frame x to*/
            _KeyFrame_x_to = new EasingDoubleKeyFrame();
            _KeyFrame_x_to.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0));
            _KeyFrame_x_to.Value = 1;
            _Animation_X.KeyFrames.Add(_KeyFrame_x_to);

            Storyboard.SetTargetProperty(_Animation_X, "(UIElement.RenderTransform).(CompositeTransform.TranslateX)");

            _Storyboard.Children.Add(_Animation_X);

            /***animation y***/
            _Animation_Y = new DoubleAnimationUsingKeyFrames();

            /*key frame 1*/
            _KeyFrame_y_from = new EasingDoubleKeyFrame();
            _KeyFrame_y_from.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0));
            _KeyFrame_y_from.Value = 0;
            _Animation_Y.KeyFrames.Add(_KeyFrame_y_from);

            /*key frame 2*/
            _KeyFrame_y_to = new EasingDoubleKeyFrame();
            _KeyFrame_y_to.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(1));
            _KeyFrame_y_to.Value = 1;
            _Animation_Y.KeyFrames.Add(_KeyFrame_y_to);

            Storyboard.SetTargetProperty(_Animation_Y, "(UIElement.RenderTransform).(CompositeTransform.TranslateY)");
            _Storyboard.Children.Add(_Animation_Y);
        }
Exemple #5
0
        public static void FadeOut(this FrameworkElement element, Action callback = null, int duration = 300)
        {
            var storyboard = new Storyboard();
            var ms300 = TimeSpan.FromMilliseconds(duration);

            element.RenderTransformOrigin = new Point(0.5, 0.5);
            var transform = element.RenderTransform as CompositeTransform;
            if (transform == null)
                element.RenderTransform = transform = new CompositeTransform();
            transform.ScaleX = 1;
            transform.ScaleY = 1;
            element.Opacity = 1;

            // opacity
            var anim = new DoubleAnimation() { Duration = ms300, To = 0 };
            Storyboard.SetTarget(anim, element);
            Storyboard.SetTargetProperty(anim, "Opacity");
            storyboard.Children.Add(anim);

            // scalex
            var bump = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(80));
            var kfanim = new DoubleAnimationUsingKeyFrames() { Duration = ms300 };
            kfanim.KeyFrames.Add(new EasingDoubleKeyFrame() { KeyTime = bump, Value = 1.02 });
            kfanim.KeyFrames.Add(new EasingDoubleKeyFrame() { KeyTime = ms300, Value = 0.9 });
            Storyboard.SetTarget(kfanim, element);
            Storyboard.SetTargetProperty(kfanim, "(UIElement.RenderTransform).(CompositeTransform.ScaleX)");
            storyboard.Children.Add(kfanim);

            // scaley
            kfanim = new DoubleAnimationUsingKeyFrames() { Duration = ms300 };
            kfanim.KeyFrames.Add(new EasingDoubleKeyFrame() { KeyTime = bump, Value = 1.02 });
            kfanim.KeyFrames.Add(new EasingDoubleKeyFrame() { KeyTime = ms300, Value = 0.9 });
            Storyboard.SetTarget(kfanim, element);
            Storyboard.SetTargetProperty(kfanim, "(UIElement.RenderTransform).(CompositeTransform.ScaleY)");
            storyboard.Children.Add(kfanim);

            storyboard.Begin(callback);
        }
Exemple #6
0
        private void Init()
        {
            _Storyboard = new Storyboard();
            _Storyboard.Completed += _Storyboard_Completed;

            /***animation ***/
            _Animation = new DoubleAnimationUsingKeyFrames();

            /*key frame from*/
            _KeyFrame_from = new EasingDoubleKeyFrame();
            _KeyFrame_from.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0));
            _KeyFrame_from.Value = 0;
            _Animation.KeyFrames.Add(_KeyFrame_from);

            /*key frame to*/
            _KeyFrame_to = new EasingDoubleKeyFrame();
            _KeyFrame_to.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(1));
            _KeyFrame_to.Value = 1;
            _Animation.KeyFrames.Add(_KeyFrame_to);

            Storyboard.SetTargetProperty(_Animation, "(UIElement.RenderTransform).(CompositeTransform.Rotation)");
            _Storyboard.Children.Add(_Animation);
        }
Exemple #7
0
        private void Init()
        {
            _Storyboard = new Storyboard();
            _Storyboard.Completed += _Storyboard_Completed;

            /***animation x***/
            _Animation = new DoubleAnimationUsingKeyFrames();

            /*key frame 1*/
            _KeyFrame_from = new EasingDoubleKeyFrame();
            _KeyFrame_from.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0));
            _KeyFrame_from.Value = 0;
            _Animation.KeyFrames.Add(_KeyFrame_from);

            /*key frame 2*/
            _KeyFrame_to = new EasingDoubleKeyFrame();
            _KeyFrame_to.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(1));
            _KeyFrame_to.Value = 0;
            _Animation.KeyFrames.Add(_KeyFrame_to);

            Storyboard.SetTargetProperty(_Animation, "(UIElement.Opacity)");
            _Storyboard.Children.Add(_Animation);
        }
Exemple #8
0
        public static void PropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            int half = 30;
            int arc = 5;

            if (e.OldValue == null)
            {
                return;
            }

            FrameworkElement fe = d as FrameworkElement;
            fe.RenderTransformOrigin = new Point(0.5, 0.5);

            RotateTransform rotate = fe.RenderTransform as RotateTransform;
            if (rotate == null)
            {
                rotate = new RotateTransform();
                rotate.CenterX = 0.5;
                rotate.CenterY = 0.5;
                fe.RenderTransform = rotate;
            }

            DoubleAnimationUsingKeyFrames da = new DoubleAnimationUsingKeyFrames();
            da.KeyFrames.Add(new EasingDoubleKeyFrame() { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(0)), Value = 0 });
            da.KeyFrames.Add(new EasingDoubleKeyFrame() { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(half)), Value = arc });
            da.KeyFrames.Add(new EasingDoubleKeyFrame() { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(half * 3)), Value = -arc });
            da.KeyFrames.Add(new EasingDoubleKeyFrame() { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(half * 4)), Value = 0 });

            Storyboard sb = new Storyboard();
            Storyboard.SetTarget(da, rotate);
            Storyboard.SetTargetProperty(da, "Angle");

            sb.Children.Add(da);

            sb.Begin();
        }
        public static Storyboard CreateFadIn(
            this Storyboard sb,
            UIElement target,
            double from,
            double to,
            double timeSecs = 1.0,
            double delay = 0)
        {
            if (sb == null)
                throw new NullReferenceException("The storyboard could not be Null");
            
            DoubleAnimationUsingKeyFrames animA = new DoubleAnimationUsingKeyFrames();
            EasingDoubleKeyFrame d1;
            EasingDoubleKeyFrame d2;

            d1 = new EasingDoubleKeyFrame();
            d1.Value = from;
            d1.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(delay));

            d2 = new EasingDoubleKeyFrame();
            d2.Value = to;
            d2.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(delay + timeSecs));

            animA.KeyFrames.Add(d1);
            animA.KeyFrames.Add(d2);
            animA.EnableDependentAnimation = true;

            sb.Children.Add(animA);

            Storyboard.SetTarget(animA, target);
            Storyboard.SetTargetProperty(animA, UI_ELEMENT_OPACITY);

            sb.SetStoryboardDuration(new Duration(TimeSpan.FromSeconds(delay + timeSecs)));

            return sb;
        }
Exemple #10
0
        private void MoveJoystick(double moveX, double moveY)
        {
            Storyboard sb = new Storyboard();
            KeyTime ktStart = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(0));
            KeyTime ktEnd = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(100));

            DoubleAnimationUsingKeyFrames animationFirstX = new DoubleAnimationUsingKeyFrames();
            DoubleAnimationUsingKeyFrames animationFirstY = new DoubleAnimationUsingKeyFrames();

            ellipseButton.RenderTransform = new CompositeTransform();

            Storyboard.SetTargetProperty(animationFirstX, "(UIElement.Projection).(PlaneProjection.GlobalOffsetX)");
            Storyboard.SetTarget(animationFirstX, ellipseButton);
            animationFirstX.KeyFrames.Add(new EasingDoubleKeyFrame { KeyTime = ktStart, Value = lastX });
            animationFirstX.KeyFrames.Add(new EasingDoubleKeyFrame { KeyTime = ktEnd, Value = moveX });

            Storyboard.SetTargetProperty(animationFirstY, "(UIElement.Projection).(PlaneProjection.GlobalOffsetY)");
            Storyboard.SetTarget(animationFirstY, ellipseButton);
            animationFirstY.KeyFrames.Add(new EasingDoubleKeyFrame { KeyTime = ktStart, Value = lastY });
            animationFirstY.KeyFrames.Add(new EasingDoubleKeyFrame { KeyTime = ktEnd, Value = moveY });

            sb.Children.Add(animationFirstX);
            sb.Children.Add(animationFirstY);
            sb.Begin();

            lastX = moveX;
            lastY = moveY;
        }
        /// <summary>
        /// Helper method to create animation storyboards to animate jobs firing from
        /// UserGroups to the Mac.
        /// </summary>
        /// <param name="from">Point to fire from</param>
        /// <param name="to">Point to fire at</param>
        /// <param name="color">Color of object to fire</param>
        /// <returns>Storyboard of requested animation</returns>
        private Storyboard AnimateJobCreation(Point from, Point to, Color color)
        {            
            // Initialize a new instance of the CompositeTransform which allows you 
            // apply multiple different transforms to the animated object
            this.JobIcon.Fill = new SolidColorBrush(color);
            this.JobIcon.RenderTransform = new CompositeTransform();

            // Create the timelines
            DoubleAnimationUsingKeyFrames animationX = new DoubleAnimationUsingKeyFrames();
            DoubleAnimationUsingKeyFrames animationY = new DoubleAnimationUsingKeyFrames();
            DoubleAnimationUsingKeyFrames opacity = new DoubleAnimationUsingKeyFrames();

            // Set up Easing functions
            ExponentialEase easingFunction = new ExponentialEase();
            easingFunction.EasingMode = EasingMode.EaseInOut;

            // Add key frames to the timeline
            animationX.KeyFrames.Add(new EasingDoubleKeyFrame { KeyTime = TimeSpan.Zero, Value = from.X });
            animationX.KeyFrames.Add(new EasingDoubleKeyFrame { KeyTime = TimeSpan.FromMilliseconds(MILLI_PER_SEC / 2), Value = to.X, EasingFunction = easingFunction });
            animationY.KeyFrames.Add(new EasingDoubleKeyFrame { KeyTime = TimeSpan.Zero, Value = from.Y });
            animationY.KeyFrames.Add(new EasingDoubleKeyFrame { KeyTime = TimeSpan.FromMilliseconds(MILLI_PER_SEC / 2), Value = to.Y, EasingFunction = easingFunction });
            opacity.KeyFrames.Add(new EasingDoubleKeyFrame { KeyTime = TimeSpan.Zero, Value = 1 });
            opacity.KeyFrames.Add(new EasingDoubleKeyFrame { KeyTime = TimeSpan.FromMilliseconds((MILLI_PER_SEC / 2) - (MILLI_PER_SEC / 5)), Value = 1 });
            opacity.KeyFrames.Add(new EasingDoubleKeyFrame { KeyTime = TimeSpan.FromMilliseconds(MILLI_PER_SEC / 2), Value = 0, EasingFunction = easingFunction });

            // Notice the first parameter takes a timeline object not the storyboard itself
            Storyboard.SetTargetProperty(animationX, "(UIElement.RenderTransform).(CompositeTransform.TranslateX)");
            Storyboard.SetTargetProperty(animationY, "(UIElement.RenderTransform).(CompositeTransform.TranslateY)");
            Storyboard.SetTargetProperty(opacity, "(UIElement.Opacity)");
            Storyboard.SetTarget(animationX, JobIcon);
            Storyboard.SetTarget(animationY, JobIcon);
            Storyboard.SetTarget(opacity, JobIcon);

            // Create the storyboards
            Storyboard storyboard = new Storyboard() { };
            // Add the timelines to your storyboard
            storyboard.Children.Add(animationX);
            storyboard.Children.Add(animationY);
            storyboard.Children.Add(opacity);

            return storyboard;
        }
        private async void OnBorderTapped(object sender, TappedRoutedEventArgs e)
        {
            if (_inAnimation)
            {
                return;
            }

            _inAnimation = true;
            _onBorderTappedCall++;
            var currentCall = _onBorderTappedCall;
            //var border = (Border)sender;
            //var grid = border.GetFirstAncestorOfType<UniformGrid>();

            //var sb = new Storyboard();

            //var beginTime = TimeSpan.Zero;

            //if (_isArrangedInGrid)
            //{
            //    var center = new Point(
            //        (grid.ActualWidth - border.ActualWidth) / 2,
            //        (grid.ActualHeight - border.ActualHeight) / 2);

            //    foreach (var child in grid.Children)
            //    {
            //        child.RenderTransform = new CompositeTransform();
            //        var nc = (NamedColor)((FrameworkElement)child).DataContext;
            //        var hsv = nc.Color.ToHsv();
            //        var targetX = center.X + center.X * Math.Sin(hsv.H * Math.PI / 180) * (0.25 + 0.75 * hsv.V);
            //        var targetY = center.Y - center.Y * Math.Cos(hsv.H * Math.PI / 180) * (0.25 + 0.75 * hsv.V);
            //        var actualPosition = child.TransformToVisual(grid).TransformPoint(new Point(0, 0));
            //        //Debug.WriteLine(actualPosition);
            //        var deltaX = targetX - actualPosition.X;
            //        var deltaY = targetY - actualPosition.Y;

            //        var xa = new DoubleAnimation();
            //        xa.BeginTime = beginTime;
            //        xa.Duration = TimeSpan.FromSeconds(1);
            //        xa.To = deltaX;
            //        Storyboard.SetTarget(xa, child.RenderTransform);
            //        Storyboard.SetTargetProperty(xa, "TranslateX");
            //        sb.Children.Add(xa);

            //        var ya = new DoubleAnimation();
            //        ya.BeginTime = beginTime;
            //        ya.Duration = TimeSpan.FromSeconds(1);
            //        ya.To = deltaY;
            //        Storyboard.SetTarget(ya, child.RenderTransform);
            //        Storyboard.SetTargetProperty(ya, "TranslateY");
            //        sb.Children.Add(ya);

            //        var aa = new DoubleAnimation();
            //        aa.BeginTime = beginTime;
            //        aa.Duration = TimeSpan.FromSeconds(1);
            //        aa.To = hsv.H;
            //        Storyboard.SetTarget(aa, child.RenderTransform);
            //        Storyboard.SetTargetProperty(aa, "Rotation");
            //        sb.Children.Add(aa);

            //        beginTime += TimeSpan.FromMilliseconds(5);
            //    }
            //}
            //else
            //{
            //    foreach (var child in grid.Children)
            //    {
            //        var nc = (NamedColor)((FrameworkElement)child).DataContext;

            //        var xa = new DoubleAnimation();
            //        xa.BeginTime = beginTime;
            //        xa.Duration = TimeSpan.FromSeconds(1);
            //        xa.To = 0;
            //        Storyboard.SetTarget(xa, child.RenderTransform);
            //        Storyboard.SetTargetProperty(xa, "TranslateX");
            //        sb.Children.Add(xa);

            //        var ya = new DoubleAnimation();
            //        ya.BeginTime = beginTime;
            //        ya.Duration = TimeSpan.FromSeconds(1);
            //        ya.To = 0;
            //        Storyboard.SetTarget(ya, child.RenderTransform);
            //        Storyboard.SetTargetProperty(ya, "TranslateY");
            //        sb.Children.Add(ya);

            //        var aa = new DoubleAnimation();
            //        aa.BeginTime = beginTime;
            //        aa.Duration = TimeSpan.FromSeconds(1);
            //        aa.To = 0;
            //        Storyboard.SetTarget(aa, child.RenderTransform);
            //        Storyboard.SetTargetProperty(aa, "Rotation");
            //        sb.Children.Add(aa);

            //        beginTime += TimeSpan.FromMilliseconds(5);
            //    }
            //}

            //sb.Begin();
            //_isArrangedInGrid = !_isArrangedInGrid;

            var border = (Border)sender;
            var grid = border.GetFirstAncestorOfType<UniformGrid>();

            if (_isArrangedInGrid)
            {
                var center = new Point(
                    (grid.ActualWidth - border.ActualWidth) / 2,
                    (grid.ActualHeight - border.ActualHeight) / 2);

                {
                    var sb1 = new Storyboard();

                    var beginTime = TimeSpan.Zero;

                    foreach (var child in grid.Children)
                    {
                        child.RenderTransform = new CompositeTransform();
                        child.RenderTransformOrigin = new Point(0.5, 0.5); 
                        var nc = (NamedColor)((FrameworkElement)child).DataContext;
                        var hsv = nc.Color.ToHsl();
                        var targetX = center.X +
                                        center.X * Math.Sin(hsv.H * Math.PI / 180) *
                                        (0.25 + 0.75 * Math.Min(hsv.L, hsv.S));
                        var targetY = center.Y -
                                        center.Y * Math.Cos(hsv.H * Math.PI / 180) *
                                        (0.25 + 0.75 * Math.Min(hsv.L, hsv.S));
                        var actualPosition =
                            child.TransformToVisual(grid)
                                    .TransformPoint(new Point(0, 0));
                        //Debug.WriteLine(actualPosition);
                        var deltaX = targetX - actualPosition.X;
                        var deltaY = targetY - actualPosition.Y;

                        var xa = new DoubleAnimation();
                        xa.BeginTime = beginTime;
                        xa.Duration = TimeSpan.FromSeconds(1);
                        xa.To = deltaX;
                        Storyboard.SetTarget(xa, child.RenderTransform);
                        Storyboard.SetTargetProperty(xa, "TranslateX");
                        sb1.Children.Add(xa);

                        var ya = new DoubleAnimation();
                        ya.BeginTime = beginTime;
                        ya.Duration = TimeSpan.FromSeconds(1);
                        ya.To = deltaY;
                        Storyboard.SetTarget(ya, child.RenderTransform);
                        Storyboard.SetTargetProperty(ya, "TranslateY");
                        sb1.Children.Add(ya);

                        var aa = new DoubleAnimation();
                        aa.BeginTime = beginTime;
                        aa.Duration = TimeSpan.FromSeconds(1);
                        aa.To = hsv.H;
                        Storyboard.SetTarget(aa, child.RenderTransform);
                        Storyboard.SetTargetProperty(aa, "Rotation");
                        sb1.Children.Add(aa);
                    }

                    await sb1.BeginAsync();
                }

                if (currentCall != _onBorderTappedCall)
                {
                    return;
                }

                const double revolutionDurationInS = 30d;

                foreach (var child in grid.Children)
                {
                    child.RenderTransform = new CompositeTransform();
                    child.RenderTransformOrigin = new Point(0.5, 0.5); 
                    var nc = (NamedColor)((FrameworkElement)child).DataContext;
                    var hsv = nc.Color.ToHsl();
                    var actualPosition = child.TransformToVisual(grid).TransformPoint(new Point(0, 0));

                    var sb = new Storyboard();
                    sb.RepeatBehavior = RepeatBehavior.Forever;

                    var minX = center.X - center.X * (0.25 + 0.75 * Math.Min(hsv.L, hsv.S)) - actualPosition.X;
                    var midX = center.X - actualPosition.X;
                    var maxX = center.X + center.X * (0.25 + 0.75 * Math.Min(hsv.L, hsv.S)) - actualPosition.X;
                    var minY = center.Y - center.Y * (0.25 + 0.75 * Math.Min(hsv.L, hsv.S)) - actualPosition.Y;
                    var midY = center.Y - actualPosition.Y;
                    var maxY = center.Y + center.Y * (0.25 + 0.75 * Math.Min(hsv.L, hsv.S)) - actualPosition.Y;

                    var xa = new DoubleAnimationUsingKeyFrames();
                    xa.KeyFrames.Add(new DiscreteDoubleKeyFrame { KeyTime = TimeSpan.Zero, Value = midX});
                    xa.KeyFrames.Add(new EasingDoubleKeyFrame { KeyTime = TimeSpan.FromSeconds(revolutionDurationInS * 0.25), Value = maxX, EasingFunction = new SineEase { EasingMode = EasingMode.EaseOut } });
                    xa.KeyFrames.Add(new EasingDoubleKeyFrame { KeyTime = TimeSpan.FromSeconds(revolutionDurationInS * 0.50), Value = midX, EasingFunction = new SineEase { EasingMode = EasingMode.EaseIn } });
                    xa.KeyFrames.Add(new EasingDoubleKeyFrame { KeyTime = TimeSpan.FromSeconds(revolutionDurationInS * 0.75), Value = minX, EasingFunction = new SineEase { EasingMode = EasingMode.EaseOut } });
                    xa.KeyFrames.Add(new EasingDoubleKeyFrame { KeyTime = TimeSpan.FromSeconds(revolutionDurationInS * 1.00), Value = midX, EasingFunction = new SineEase { EasingMode = EasingMode.EaseIn } });
                    Storyboard.SetTarget(xa, child.RenderTransform);
                    Storyboard.SetTargetProperty(xa, "TranslateX");
                    sb.Children.Add(xa);

                    var ya = new DoubleAnimationUsingKeyFrames();
                    ya.KeyFrames.Add(new DiscreteDoubleKeyFrame { KeyTime = TimeSpan.Zero, Value = minY });
                    ya.KeyFrames.Add(new EasingDoubleKeyFrame { KeyTime = TimeSpan.FromSeconds(revolutionDurationInS * 0.25), Value = midY, EasingFunction = new SineEase { EasingMode = EasingMode.EaseIn } });
                    ya.KeyFrames.Add(new EasingDoubleKeyFrame { KeyTime = TimeSpan.FromSeconds(revolutionDurationInS * 0.50), Value = maxY, EasingFunction = new SineEase { EasingMode = EasingMode.EaseOut } });
                    ya.KeyFrames.Add(new EasingDoubleKeyFrame { KeyTime = TimeSpan.FromSeconds(revolutionDurationInS * 0.75), Value = midY, EasingFunction = new SineEase { EasingMode = EasingMode.EaseIn } });
                    ya.KeyFrames.Add(new EasingDoubleKeyFrame { KeyTime = TimeSpan.FromSeconds(revolutionDurationInS * 1.00), Value = minY, EasingFunction = new SineEase { EasingMode = EasingMode.EaseOut } });
                    Storyboard.SetTarget(ya, child.RenderTransform);
                    Storyboard.SetTargetProperty(ya, "TranslateY");
                    sb.Children.Add(ya);

                    var aa = new DoubleAnimation();
                    aa.Duration = TimeSpan.FromSeconds(revolutionDurationInS);
                    aa.From = 0;
                    aa.To = 360;
                    Storyboard.SetTarget(aa, child.RenderTransform);
                    Storyboard.SetTargetProperty(aa, "Rotation");
                    sb.Children.Add(aa);
                    //sb.BeginTime =
                    //    TimeSpan.FromSeconds(hsv.H * revolutionDurationInS / 360d);
                    sb.Begin();
                    sb.Seek(TimeSpan.FromSeconds(((hsv.H + 360) % 360) * revolutionDurationInS / 360d));
                }
            }
            else
            {
                var sb = new Storyboard();
                var beginTime = TimeSpan.Zero;

                foreach (var child in grid.Children)
                {
                    //var nc = (NamedColor)((FrameworkElement)child).DataContext;

                    var xa = new DoubleAnimation();
                    xa.BeginTime = beginTime;
                    xa.Duration = TimeSpan.FromSeconds(1);
                    xa.To = 0;
                    Storyboard.SetTarget(xa, child.RenderTransform);
                    Storyboard.SetTargetProperty(xa, "TranslateX");
                    sb.Children.Add(xa);

                    var ya = new DoubleAnimation();
                    ya.BeginTime = beginTime;
                    ya.Duration = TimeSpan.FromSeconds(1);
                    ya.To = 0;
                    Storyboard.SetTarget(ya, child.RenderTransform);
                    Storyboard.SetTargetProperty(ya, "TranslateY");
                    sb.Children.Add(ya);

                    var aa = new DoubleAnimation();
                    aa.BeginTime = beginTime;
                    aa.Duration = TimeSpan.FromSeconds(1);
                    aa.To = 0;
                    Storyboard.SetTarget(aa, child.RenderTransform);
                    Storyboard.SetTargetProperty(aa, "Rotation");
                    sb.Children.Add(aa);

                    //beginTime += TimeSpan.FromMilliseconds(5);
                }

                await sb.BeginAsync();
            }

            _isArrangedInGrid = !_isArrangedInGrid;
            _inAnimation = false;
        }
        /// <summary>
        /// Runs the cascades animation.
        /// </summary>
        /// <exception cref="System.InvalidOperationException"></exception>
        public void Cascade()
        {
            if (!_isLoaded ||
                _layoutGrid == null)
            {
                return;
            }

            if (Rows < 1)
                Rows = 1;
            if (Columns < 1)
                Columns = 1;

            _layoutGrid.Children.Clear();
            _layoutGrid.RowDefinitions.Clear();
            _layoutGrid.ColumnDefinitions.Clear();

            for (int row = 0; row < Rows; row++)
            {
                _layoutGrid.RowDefinitions.Add(new RowDefinition());
            }

            for (int column = 0; column < Columns; column++)
            {
                _layoutGrid.ColumnDefinitions.Add(new ColumnDefinition());
            }

            var sb = new Storyboard();

            var totalDurationInSeconds = RowDelay.TotalSeconds * (Rows - 1) +
                                         ColumnDelay.TotalSeconds * (Columns - 1) +
                                         TileDuration.TotalSeconds;

            CascadeDirection direction = this.CascadeDirection;

            if (direction == CascadeDirection.Random)
            {
                direction = (CascadeDirection)Random.Next((int)CascadeDirection.Random);
            }

            int startColumn;
            int exclusiveEndColumn;
            int columnIncrement;

            int startRow;
            int exclusiveEndRow;
            int rowIncrement;

            switch (direction)
            {
                case CascadeDirection.Shuffle:
                case CascadeDirection.TopLeft:
                    startColumn = 0;
                    exclusiveEndColumn = Columns;
                    columnIncrement = 1;
                    startRow = 0;
                    exclusiveEndRow = Rows;
                    rowIncrement = 1;
                    break;
                case CascadeDirection.TopRight:
                    startColumn = Columns - 1;
                    exclusiveEndColumn = -1;
                    columnIncrement = -1;
                    startRow = 0;
                    exclusiveEndRow = Rows;
                    rowIncrement = 1;
                    break;
                case CascadeDirection.BottomRight:
                    startColumn = Columns - 1;
                    exclusiveEndColumn = -1;
                    columnIncrement = -1;
                    startRow = Rows - 1;
                    exclusiveEndRow = -1;
                    rowIncrement = -1;
                    break;
                case CascadeDirection.BottomLeft:
                    startColumn = 0;
                    exclusiveEndColumn = Columns;
                    columnIncrement = 1;
                    startRow = Rows - 1;
                    exclusiveEndRow = -1;
                    rowIncrement = -1;
                    break;
                default:
                    throw new InvalidOperationException();
            }

            List<Tuple<int, int>> rectCoords = new List<Tuple<int, int>>(Rows * Columns);
            List<Rectangle> rects = new List<Rectangle>(Rows * Columns);
            List<PlaneProjection> projs = new List<PlaneProjection>(Rows * Columns);

            for (int row = startRow; row != exclusiveEndRow; row = row + rowIncrement)
                for (int column = startColumn; column != exclusiveEndColumn; column = column + columnIncrement)
                {
                    var rect = new Rectangle();
                    rects.Add(rect);

                    Grid.SetRow(rect, row);
                    Grid.SetColumn(rect, column);
                    rectCoords.Add(new Tuple<int, int>(column, row));

                    var brush = new ImageBrush();
                    brush.ImageSource = this.ImageSource;
                    rect.Fill = brush;

                    var transform = new CompositeTransform();
                    transform.TranslateX = -column;
                    transform.ScaleX = Columns;
                    transform.TranslateY = -row;
                    transform.ScaleY = Rows;
                    brush.RelativeTransform = transform;

                    var projection = new PlaneProjection();
                    projection.CenterOfRotationY = 0;
                    rect.Projection = projection;
                    projs.Add(projection);

                    _layoutGrid.Children.Add(rect);
                }

            var indices = new List<int>(Rows * Columns);

            for (int i = 0; i < Rows * Columns; i++)
                indices.Add(i);

            if (direction == CascadeDirection.Shuffle)
            {
                indices = indices.Shuffle();
            }

            for (int ii = 0; ii < indices.Count; ii++)
            {
                var i = indices[ii];
                var projection = projs[i];
                var rect = rects[i];
                var column = rectCoords[ii].Item1;
                var row = rectCoords[ii].Item2;
                //Debug.WriteLine("i: {0}, p: {1}, rect: {2}, c: {3}, r: {4}", i, projection.GetHashCode(), rect.GetHashCode(), column, row);
                var rotationAnimation = new DoubleAnimationUsingKeyFrames();
                Storyboard.SetTarget(rotationAnimation, projection);
                Storyboard.SetTargetProperty(rotationAnimation, "RotationX");

                var endKeyTime =
                    this.CascadeSequence == CascadeSequence.EndTogether
                        ? TimeSpan.FromSeconds(totalDurationInSeconds)
                        : TimeSpan.FromSeconds(
                            (double)row * RowDelay.TotalSeconds +
                            (double)column * ColumnDelay.TotalSeconds +
                            TileDuration.TotalSeconds);

                rotationAnimation.KeyFrames.Add(
                    new DiscreteDoubleKeyFrame
                    {
                        KeyTime = TimeSpan.Zero,
                        Value = 90
                    });
                rotationAnimation.KeyFrames.Add(
                    new DiscreteDoubleKeyFrame
                    {
                        KeyTime = TimeSpan.FromSeconds((double)row * RowDelay.TotalSeconds + (double)column * ColumnDelay.TotalSeconds),
                        Value = 90
                    });
                rotationAnimation.KeyFrames.Add(
                    new EasingDoubleKeyFrame
                    {
                        KeyTime = endKeyTime,
                        EasingFunction = CascadeInEasingFunction,
                        Value = 0
                    });

                sb.Children.Add(rotationAnimation);

                var opacityAnimation = new DoubleAnimationUsingKeyFrames();
                Storyboard.SetTarget(opacityAnimation, rect);
                Storyboard.SetTargetProperty(opacityAnimation, "Opacity");

                opacityAnimation.KeyFrames.Add(
                    new DiscreteDoubleKeyFrame
                    {
                        KeyTime = TimeSpan.Zero,
                        Value = 0
                    });
                opacityAnimation.KeyFrames.Add(
                    new DiscreteDoubleKeyFrame
                    {
                        KeyTime = TimeSpan.FromSeconds((double)row * RowDelay.TotalSeconds + (double)column * ColumnDelay.TotalSeconds),
                        Value = 0
                    });
                opacityAnimation.KeyFrames.Add(
                    new EasingDoubleKeyFrame
                    {
                        KeyTime = endKeyTime,
                        EasingFunction = CascadeInEasingFunction,
                        Value = 1
                    });

                sb.Children.Add(opacityAnimation);
            }

            sb.Begin();
        }
Exemple #14
0
        public static Storyboard MakeTranslateStory(DependencyObject element, double fromValue, double toValue, TimeSpan lastTime, bool isX)
        {
            Storyboard sb = new Storyboard();

            DoubleAnimationUsingKeyFrames frames = new DoubleAnimationUsingKeyFrames();
            Storyboard.SetTargetProperty(frames, isX ? "(UIElement.RenderTransform).(CompositeTransform.TranslateX)" : "(UIElement.RenderTransform).(CompositeTransform.TranslateY)");
            Storyboard.SetTarget(frames, element);

            EasingDoubleKeyFrame frame1 = new EasingDoubleKeyFrame();
            frame1.KeyTime = new TimeSpan(0, 0, 0, 0);
            frame1.Value = fromValue;

            EasingDoubleKeyFrame frame2 = new EasingDoubleKeyFrame();
            frame2.KeyTime = lastTime;
            frame2.Value = toValue;
            frame2.EasingFunction = new CubicEase() { EasingMode = EasingMode.EaseOut };

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

            sb.FillBehavior = FillBehavior.HoldEnd;
            sb.Children.Add(frames);

            return sb;
        }
        /// <summary>
        /// Scale X Animation Keyframes for tile animations.
        /// </summary>
        /// <returns></returns>
        private DoubleAnimationUsingKeyFrames CreateScaleXKeyFrames(int delay = 0)
        {
            var animation = new DoubleAnimationUsingKeyFrames();

            Storyboard.SetTargetProperty(animation, "(UIElement.RenderTransform).(CompositeTransform.ScaleX)");

            var frame = new EasingDoubleKeyFrame();
            frame.KeyTime = new KeyTime();
            frame.KeyTime = TimeSpan.FromMilliseconds(0);
            frame.Value = 0;

            var frameTwo = new EasingDoubleKeyFrame();
            frameTwo.KeyTime = new KeyTime();
            frameTwo.KeyTime = TimeSpan.FromMilliseconds(0 + delay);
            frameTwo.Value = 0;

            var frameThree = new EasingDoubleKeyFrame();
            frameThree.KeyTime = new KeyTime();
            frameThree.KeyTime = TimeSpan.FromMilliseconds(100 + delay);
            frameThree.Value = 1;

            //var frameThree = new EasingDoubleKeyFrame();
            //frameThree.KeyTime = new KeyTime();
            //frameThree.KeyTime = TimeSpan.FromMilliseconds(1000 + delay);
            //frameThree.Value = 1;

            animation.KeyFrames.Add(frame);
            animation.KeyFrames.Add(frameTwo);
            animation.KeyFrames.Add(frameThree);

            return animation;
        }
Exemple #16
0
        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();
            }
        }
Exemple #17
0
        public static Storyboard MakeOpacityStory(DependencyObject element, double fromValue, double toValue, TimeSpan lastTime)
        {
            Storyboard sb = new Storyboard();

            DoubleAnimationUsingKeyFrames frames = new DoubleAnimationUsingKeyFrames();
            Storyboard.SetTargetProperty(frames, "Opacity");
            Storyboard.SetTarget(frames, element);

            EasingDoubleKeyFrame frame1 = new EasingDoubleKeyFrame();
            frame1.KeyTime = new TimeSpan(0, 0, 0, 0);
            frame1.Value = fromValue;

            EasingDoubleKeyFrame frame2 = new EasingDoubleKeyFrame();
            frame2.KeyTime = lastTime;
            frame2.Value = toValue;

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

            sb.FillBehavior = FillBehavior.HoldEnd;
            sb.Children.Add(frames);

            return sb;
        }
        private static DoubleAnimationUsingKeyFrames CreateScaleYKeyFrames(int delay = 0)
        {
            var animation = new DoubleAnimationUsingKeyFrames();

            Storyboard.SetTargetProperty(animation, "(UIElement.RenderTransform).(CompositeTransform.ScaleY)");

            var frameA = new EasingDoubleKeyFrame();
            frameA.KeyTime = new KeyTime();
            frameA.KeyTime = TimeSpan.FromMilliseconds(0);
            frameA.Value = 0;

            var frameB = new EasingDoubleKeyFrame();
            frameB.KeyTime = new KeyTime();
            frameB.KeyTime = TimeSpan.FromMilliseconds(0 + delay);
            frameB.Value = 0;

            var frameC = new EasingDoubleKeyFrame();
            frameC.KeyTime = new KeyTime();
            frameC.KeyTime = TimeSpan.FromMilliseconds(100 + delay);
            frameC.Value = 1;

            animation.KeyFrames.Add(frameA);
            animation.KeyFrames.Add(frameB);
            animation.KeyFrames.Add(frameC);

            return animation;
        }
Exemple #19
0
        public static Storyboard MakeScaleAndDispearStory(DependencyObject element, TimeSpan lastTime)
        {
            Storyboard sb = new Storyboard();

            DoubleAnimationUsingKeyFrames frames = new DoubleAnimationUsingKeyFrames();
            Storyboard.SetTargetProperty(frames, "Opacity");
            Storyboard.SetTarget(frames, element);

            EasingDoubleKeyFrame frame1 = new EasingDoubleKeyFrame();
            frame1.KeyTime = new TimeSpan(0, 0, 0, 0);
            frame1.Value = 1;

            EasingDoubleKeyFrame frame2 = new EasingDoubleKeyFrame();
            frame2.KeyTime = lastTime;
            frame2.Value = 0;

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

            DoubleAnimationUsingKeyFrames frames1 = new DoubleAnimationUsingKeyFrames();
            Storyboard.SetTargetProperty(frames1, "(UIElement.RenderTransform).(CompositeTransform.ScaleX)");
            Storyboard.SetTarget(frames1, element);

            EasingDoubleKeyFrame frame11 = new EasingDoubleKeyFrame();
            frame11.KeyTime = new TimeSpan(0, 0, 0, 0);
            frame11.Value = 1;

            EasingDoubleKeyFrame frame12 = new EasingDoubleKeyFrame();
            frame12.KeyTime = lastTime;
            frame12.Value = 5;

            frames1.KeyFrames.Add(frame11);
            frames1.KeyFrames.Add(frame12);

            DoubleAnimationUsingKeyFrames frames2 = new DoubleAnimationUsingKeyFrames();
            Storyboard.SetTargetProperty(frames2, "(UIElement.RenderTransform).(CompositeTransform.ScaleY)");
            Storyboard.SetTarget(frames2, element);

            EasingDoubleKeyFrame frame21 = new EasingDoubleKeyFrame();
            frame21.KeyTime = new TimeSpan(0, 0, 0, 0);
            frame21.Value = 1;

            EasingDoubleKeyFrame frame22 = new EasingDoubleKeyFrame();
            frame22.KeyTime = lastTime;
            frame22.Value = 5;

            frames2.KeyFrames.Add(frame21);
            frames2.KeyFrames.Add(frame22);

            sb.FillBehavior = FillBehavior.HoldEnd;
            sb.Children.Add(frames1);
            sb.Children.Add(frames2);
            sb.Children.Add(frames);
            return sb;
        }
        private DoubleAnimationUsingKeyFrames CreateOpacityKeyFrames(int delay = 0)
        {
            var opacityAnimation = new DoubleAnimationUsingKeyFrames();

            Storyboard.SetTargetProperty(opacityAnimation, "(UIElement.Opacity)");

            var oFrameZero = new EasingDoubleKeyFrame();
            oFrameZero.KeyTime = new KeyTime();
            oFrameZero.KeyTime = TimeSpan.FromMilliseconds(0);
            oFrameZero.Value = 1;

            var oFrameOne = new EasingDoubleKeyFrame();
            oFrameOne.KeyTime = new KeyTime();
            oFrameOne.KeyTime = TimeSpan.FromMilliseconds(500 + delay);
            oFrameOne.Value = 1;


            var oFrameTwo = new EasingDoubleKeyFrame();
            oFrameTwo.KeyTime = new KeyTime();
            oFrameTwo.KeyTime = TimeSpan.FromMilliseconds(2000 + delay);
            oFrameTwo.Value = 0;

            oFrameTwo.EasingFunction = new QuinticEase();
            oFrameTwo.EasingFunction.EasingMode = EasingMode.EaseOut;

            opacityAnimation.KeyFrames.Add(oFrameZero);
            opacityAnimation.KeyFrames.Add(oFrameOne);
            opacityAnimation.KeyFrames.Add(oFrameTwo);

            return opacityAnimation;
        }
Exemple #21
0
        /// <summary>
        /// Provides the feathered animation for items
        /// when the Expander View goes from collapsed to expanded.
        /// </summary>
        internal void AnimateContainerDropDown()
        {
            for (int i = 0; i < Items.Count; i++)
            {
                FrameworkElement container = ContainerFromIndex(i) as FrameworkElement;

                if (container == null)
                {
                    break;
                }

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

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

                DoubleAnimationUsingKeyFrames transAnimation = new DoubleAnimationUsingKeyFrames();

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

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

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

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

                Storyboard.SetTarget(transAnimation, translation);
                Storyboard.SetTargetProperty(transAnimation, "Y");
                itemDropDown.Children.Add(transAnimation);

                DoubleAnimationUsingKeyFrames opacityAnimation = new DoubleAnimationUsingKeyFrames();

                EasingDoubleKeyFrame opacityKeyFrame1 = new EasingDoubleKeyFrame();
                opacityKeyFrame1.EasingFunction = quadraticEase;
                opacityKeyFrame1.KeyTime = TimeSpan.FromMilliseconds(0.0);
                opacityKeyFrame1.Value = 0.0;

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

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

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

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

                itemDropDown.Begin();
            }
        }
        private DoubleAnimationUsingKeyFrames CreateTranslationKeyFrames(int playerViewModelIndex, TileAnimationDirection direction, Grid tile, int delay = 0)
        {
            Point BeginPoint;
            Point EndPoint;

            var animation = new DoubleAnimationUsingKeyFrames();

            Storyboard.SetTargetProperty(animation, "(UIElement.RenderTransform).(CompositeTransform.TranslateY)");

            var dumpCircleGt = InnerDumpCircle.TransformToVisual(pageRoot);

            var animationTargetContainer = PlayerPanel.ItemContainerGenerator.ContainerFromIndex(playerViewModelIndex);

            var grid = VisualTreeHelper.GetChild(animationTargetContainer, 0) as Grid;

            var playerViewModelGt = grid.TransformToVisual(pageRoot);

            if (direction == TileAnimationDirection.Down)
            {
                BeginPoint = dumpCircleGt.TransformPoint(new Point(0, 0));

                EndPoint = playerViewModelGt.TransformPoint(new Point(0, 0));

                tile.Margin = new Thickness(BeginPoint.X + InnerDumpCircle.Width / 2 - tile.Width / 2, BeginPoint.Y - tile.Height / 2 + 10/* + InnerDumpCircle.Height / 2*/, 0, 0);
            }
            else
            {
                EndPoint = dumpCircleGt.TransformPoint(new Point(0, 0));

                BeginPoint = playerViewModelGt.TransformPoint(new Point(0, 0));

                tile.Margin = new Thickness(BeginPoint.X + InnerDumpCircle.Width / 2 + 15, tile.Height / 2 + 10, 0, 0);
            }

            var acFrame = new EasingDoubleKeyFrame();
            acFrame.KeyTime = new KeyTime();
            acFrame.KeyTime = TimeSpan.FromMilliseconds(0);
            acFrame.Value = BeginPoint.Y;

            var bcFrame = new EasingDoubleKeyFrame();
            bcFrame.KeyTime = new KeyTime();
            bcFrame.KeyTime = TimeSpan.FromMilliseconds(0 + delay);
            bcFrame.Value = BeginPoint.Y;


            var cFrame = new EasingDoubleKeyFrame();
            cFrame.KeyTime = new KeyTime();
            cFrame.KeyTime = TimeSpan.FromMilliseconds(100 + delay);
            cFrame.Value = BeginPoint.Y;

            var dFrame = new EasingDoubleKeyFrame();
            dFrame.KeyTime = new KeyTime();
            dFrame.KeyTime = TimeSpan.FromMilliseconds(500 + delay);
            dFrame.Value = EndPoint.Y;

            dFrame.EasingFunction = new QuadraticEase();
            dFrame.EasingFunction.EasingMode = EasingMode.EaseInOut;

            animation.KeyFrames.Add(acFrame);
            animation.KeyFrames.Add(bcFrame);
            animation.KeyFrames.Add(cFrame);
            animation.KeyFrames.Add(dFrame);

            return animation;
        }
        private Storyboard CreateEnterAnimation(Panel layoutRoot)
        {
            var enterAnimation = new Storyboard();
            Storyboard.SetTarget(enterAnimation, layoutRoot);

            var ad = new AnimationDescription(AnimationEffect.EnterPage, AnimationEffectTarget.Primary);
            for (int i = 0; i < layoutRoot.Children.Count; i++)
            {
                // Add a render transform to the existing one just for animations
                var element = layoutRoot.Children[i];
                var tg = new TransformGroup();
                tg.Children.Add(new TranslateTransform());
                tg.Children.Add(element.RenderTransform);
                element.RenderTransform = tg;

                // Calculate the stagger for each animation. Note that this has a max
                var delayMs = Math.Min(ad.StaggerDelay.TotalMilliseconds * i * ad.StaggerDelayFactor, ad.DelayLimit.Milliseconds);
                var delay = TimeSpan.FromMilliseconds(delayMs);

                foreach (var description in ad.Animations)
                {
                    var animation = new DoubleAnimationUsingKeyFrames();

                    // Start the animation at the right offset
                    var startSpline = new SplineDoubleKeyFrame();
                    startSpline.KeyTime = TimeSpan.FromMilliseconds(0);
                    Storyboard.SetTarget(animation, element);

                    // Hold at that offset until the stagger delay is hit
                    var middleSpline = new SplineDoubleKeyFrame();
                    middleSpline.KeyTime = delay;

                    // Animation from delayed time to last time
                    var endSpline = new SplineDoubleKeyFrame();
                    endSpline.KeySpline = new KeySpline() { ControlPoint1 = description.Control1, ControlPoint2 = description.Control2 };
                    endSpline.KeyTime = description.Duration + delay;

                    // Do the translation
                    if (description.Type == PropertyAnimationType.Translation)
                    {
                        startSpline.Value = ANIMATION_TRANSLATION_START;
                        middleSpline.Value = ANIMATION_TRANSLATION_START;
                        endSpline.Value = ANIMATION_TRANSLATION_END;

                        Storyboard.SetTargetProperty(animation, "(UIElement.RenderTransform).(TransformGroup.Children)[0].X");
                    }
                    // Opacity
                    else if (description.Type == PropertyAnimationType.Opacity)
                    {
                        startSpline.Value = ANIMATION_OPACITY_START;
                        middleSpline.Value = ANIMATION_OPACITY_START;
                        endSpline.Value = ANIMATION_OPACITY_END;

                        Storyboard.SetTargetProperty(animation, "Opacity");
                    }
                    else
                    {
                        throw new Exception("Encountered an unexpected animation type.");
                    }

                    // Put the final animation together
                    animation.KeyFrames.Add(startSpline);
                    animation.KeyFrames.Add(middleSpline);
                    animation.KeyFrames.Add(endSpline);
                    enterAnimation.Children.Add(animation);
                }
            }

            return enterAnimation;
        }
Exemple #24
0
        private void MoveJoystick(double moveX, double moveY)
        {
            Storyboard sb = new Storyboard();
            KeyTime ktStart = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(0));
            KeyTime ktEnd = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(200));

            DoubleAnimationUsingKeyFrames animationFirstX = new DoubleAnimationUsingKeyFrames();
            DoubleAnimationUsingKeyFrames animationFirstY = new DoubleAnimationUsingKeyFrames();

            stickContainer.RenderTransform = new CompositeTransform();

            Storyboard.SetTarget(animationFirstX, stickContainer.RenderTransform);
            Storyboard.SetTargetProperty(animationFirstX, "(CompositeTransform.TranslateX)");
            
            animationFirstX.KeyFrames.Add(new EasingDoubleKeyFrame() { KeyTime = ktStart, Value = lastX });
            animationFirstX.KeyFrames.Add(new EasingDoubleKeyFrame() { KeyTime = ktEnd, Value = moveX });

            Storyboard.SetTarget(animationFirstY, stickContainer.RenderTransform);
            Storyboard.SetTargetProperty(animationFirstY, "(CompositeTransform.TranslateY)");
            
            animationFirstY.KeyFrames.Add(new EasingDoubleKeyFrame() { KeyTime = ktStart, Value = lastY });
            animationFirstY.KeyFrames.Add(new EasingDoubleKeyFrame() { KeyTime = ktEnd, Value = moveY });

            sb.Children.Add(animationFirstX);
            sb.Children.Add(animationFirstY);
            sb.Begin();

            lastX = moveX;
            lastY = moveY;

            //Debug.WriteLine("Move Joystick to: " + moveX + ", " + moveY);
        }
        public void Cascade()
        {
            RH = RW = double.NaN;
            if (!_isLoaded ||
                _layoutGrid == null)
            {
                return;
            }

            if (Rows < 1)
                Rows = 1;
            if (Columns < 1)
                Columns = 1;

            _layoutGrid.Children.Clear();
            _layoutGrid.RowDefinitions.Clear();
            _layoutGrid.ColumnDefinitions.Clear();

            for (int row = 0; row < Rows; row++)
            {
                _layoutGrid.RowDefinitions.Add(new RowDefinition());
            }

            for (int column = 0; column < Columns; column++)
            {
                _layoutGrid.ColumnDefinitions.Add(new ColumnDefinition());
            }

            var sb = new Storyboard();

            var totalDurationInSeconds = RowDelay.TotalSeconds * (Rows - 1) +
                                         ColumnDelay.TotalSeconds * (Columns - 1) +
                                         TileDuration.TotalSeconds;

            CascadeDirection direction = this.CascadeDirection;

            if (direction == CascadeDirection.Random)
            {
                direction = (CascadeDirection)Random.Next((int)CascadeDirection.Random);
            }

            int startColumn;
            int exclusiveEndColumn;
            int columnIncrement;

            int startRow;
            int exclusiveEndRow;
            int rowIncrement;

            switch (direction)
            {
                case CascadeDirection.Shuffle:
                case CascadeDirection.TopLeft:
                    startColumn = 0;
                    exclusiveEndColumn = Columns;
                    columnIncrement = 1;
                    startRow = 0;
                    exclusiveEndRow = Rows;
                    rowIncrement = 1;
                    break;
                case CascadeDirection.TopRight:
                    startColumn = Columns - 1;
                    exclusiveEndColumn = -1;
                    columnIncrement = -1;
                    startRow = 0;
                    exclusiveEndRow = Rows;
                    rowIncrement = 1;
                    break;
                case CascadeDirection.BottomRight:
                    startColumn = Columns - 1;
                    exclusiveEndColumn = -1;
                    columnIncrement = -1;
                    startRow = Rows - 1;
                    exclusiveEndRow = -1;
                    rowIncrement = -1;
                    break;
                case CascadeDirection.BottomLeft:
                    startColumn = 0;
                    exclusiveEndColumn = Columns;
                    columnIncrement = 1;
                    startRow = Rows - 1;
                    exclusiveEndRow = -1;
                    rowIncrement = -1;
                    break;
                default:
                    throw new InvalidOperationException();
            }

            List<Tuple<int, int>> rectCoords = new List<Tuple<int, int>>(Rows * Columns);
            List<Rectangle> rects = new List<Rectangle>(Rows * Columns);
            //List<PlaneProjection> projs = new List<PlaneProjection>(Rows * Columns);
            //List<CompositeTransform> ct = new List<CompositeTransform>(Rows * Columns);

            //**********************开始的位置
            List<double> translateXInfo = new List<double>();
            List<double> translateYInfo = new List<double>();

            for (int row = startRow; row != exclusiveEndRow; row = row + rowIncrement)
                for (int column = startColumn; column != exclusiveEndColumn; column = column + columnIncrement)
                {
                    var rect = new Rectangle();
                    rects.Add(rect);

                    Grid.SetRow(rect, row);
                    Grid.SetColumn(rect, column);
                    rectCoords.Add(new Tuple<int, int>(column, row));

                    var brush = new ImageBrush();
                    brush.ImageSource = this.ImageSource;
                    brush.Stretch = this.Stretch;
                    rect.Fill = brush;

                    var transform = new CompositeTransform();
                    transform.TranslateX = -column;
                    transform.ScaleX = Columns;
                    transform.TranslateY = -row;
                    transform.ScaleY = Rows;
                    brush.RelativeTransform = transform;

                    var projection = new PlaneProjection();
                    projection.CenterOfRotationY = 0;
                    rect.Projection = projection;
                    //projs.Add(projection);

                    var rectTransform = new CompositeTransform();
                    rectTransform.CenterX = rectTransform.CenterY = 0.5;
                    ////////////////////////写到这
                    //rectTransform.TranslateX = -column;
                    //rectTransform.TranslateY = -row;
                    rectTransform.Rotation = 0;
                    rect.RenderTransformOrigin = new Windows.Foundation.Point(0.5, 0.5);
                    rect.RenderTransform = rectTransform;
                    //ct.Add(rectTransform);

                    //if (!double.IsNaN(RH) && !double.IsNaN(RW))
                    //{
                    //    rect.Margin = new Thickness(column * 52, row * 50, 0, 0);
                    //}

                    _layoutGrid.Children.Add(rect);

                }
            //GetRHAndRW();
            if (double.IsNaN(RH) || double.IsNaN(RW))
            {
                rects[0].SizeChanged -= sizeChanged;
                rects[0].SizeChanged += sizeChanged = (ss, ee) =>
                {
                    this.RH = ee.NewSize.Height;
                    this.RW = ee.NewSize.Width;

                    var indices = new List<int>(Rows * Columns);

                    for (int i = 0; i < Rows * Columns; i++)
                    {
                        indices.Add(i);

                        ////////////////////////写到这
                        var transform = rects[i].RenderTransform as CompositeTransform;
                        //transform.TranslateX = transform.TranslateX * RW;
                        //transform.TranslateY = transform.TranslateY * RH;

                        //*****************************恶心点,随便弄个起始位置,到时候可以根据行列信息或者奇偶信息来设置起始位置
                        //transform.TranslateX = i * RW;
                        //transform.TranslateY = i * RH;

                        if (i < Rows * Columns / 2)
                        {
                            transform.TranslateX =-RW;
                            transform.TranslateY = -RH;
                        }
                        else
                        {
                            transform.TranslateX = RW;
                            transform.TranslateY = RH;
                        }

                        translateXInfo.Add(transform.TranslateX);
                        translateYInfo.Add(transform.TranslateY);
                        System.Diagnostics.Debug.WriteLine("TX = " + transform.TranslateX + " TY = " + transform.TranslateY + "\n");
                    }

                    if (direction == CascadeDirection.Shuffle)
                    {
                        indices = indices.Shuffle();
                    }

                    for (int ii = 0; ii < indices.Count; ii++)
                    {
                        var i = indices[ii];
                        //var projection = projs[i];
                        var projection = rects[i].Projection;
                        var rect = rects[i];
                        var column = rectCoords[ii].Item1;
                        var row = rectCoords[ii].Item2;
                        //*******************拿到当前的transform
                        var transfrom = rect.RenderTransform as CompositeTransform;
                        //Debug.WriteLine("i: {0}, p: {1}, rect: {2}, c: {3}, r: {4}", i, projection.GetHashCode(), rect.GetHashCode(), column, row);
                        var rotationAnimation = new DoubleAnimationUsingKeyFrames();
                        Storyboard.SetTarget(rotationAnimation, projection);
                        Storyboard.SetTargetProperty(rotationAnimation, "RotationX");

                        var endKeyTime =
                            this.CascadeSequence == CascadeSequence.EndTogether
                                ? TimeSpan.FromSeconds(totalDurationInSeconds)
                                : TimeSpan.FromSeconds(
                                    (double)row * RowDelay.TotalSeconds +
                                    (double)column * ColumnDelay.TotalSeconds +
                                    TileDuration.TotalSeconds);

                        rotationAnimation.KeyFrames.Add(
                            new DiscreteDoubleKeyFrame
                            {
                                KeyTime = TimeSpan.Zero,
                                Value = 90
                            });
                        rotationAnimation.KeyFrames.Add(
                            new DiscreteDoubleKeyFrame
                            {
                                KeyTime = TimeSpan.FromSeconds((double)row * RowDelay.TotalSeconds + (double)column * ColumnDelay.TotalSeconds),
                                Value = 90
                            });
                        rotationAnimation.KeyFrames.Add(
                            new EasingDoubleKeyFrame
                            {
                                KeyTime = endKeyTime,
                                EasingFunction = CascadeInEasingFunction,
                                Value = 0
                            });

                        sb.Children.Add(rotationAnimation);

                        //****************************y,z的效果可以研究下如何加比较好
                         rotationAnimation = new DoubleAnimationUsingKeyFrames();
                         Storyboard.SetTarget(rotationAnimation, projection);
                         Storyboard.SetTargetProperty(rotationAnimation, "RotationY");

                         rotationAnimation.KeyFrames.Add(
                             new DiscreteDoubleKeyFrame
                             {
                                 KeyTime = TimeSpan.Zero,
                                 Value = 180
                             });
                         rotationAnimation.KeyFrames.Add(
                             new DiscreteDoubleKeyFrame
                             {
                                 KeyTime = TimeSpan.FromSeconds((double)row * RowDelay.TotalSeconds + (double)column * ColumnDelay.TotalSeconds),
                                 Value = 90
                             });
                         rotationAnimation.KeyFrames.Add(
                             new EasingDoubleKeyFrame
                             {
                                 KeyTime = endKeyTime,
                                 EasingFunction = CascadeInEasingFunction,
                                 Value = 0
                             });

                         sb.Children.Add(rotationAnimation);

                         rotationAnimation = new DoubleAnimationUsingKeyFrames();
                         Storyboard.SetTarget(rotationAnimation, projection);
                         Storyboard.SetTargetProperty(rotationAnimation, "RotationZ");

                         rotationAnimation.KeyFrames.Add(
                             new DiscreteDoubleKeyFrame
                             {
                                 KeyTime = TimeSpan.Zero,
                                 Value = 180
                             });
                         rotationAnimation.KeyFrames.Add(
                             new DiscreteDoubleKeyFrame
                             {
                                 KeyTime = TimeSpan.FromSeconds((double)row * RowDelay.TotalSeconds + (double)column * ColumnDelay.TotalSeconds),
                                 Value = 90
                             });
                         rotationAnimation.KeyFrames.Add(
                             new EasingDoubleKeyFrame
                             {
                                 KeyTime = endKeyTime,
                                 EasingFunction = CascadeInEasingFunction,
                                 Value = 0
                             });

                         sb.Children.Add(rotationAnimation);

                        var opacityAnimation = new DoubleAnimationUsingKeyFrames();
                        Storyboard.SetTarget(opacityAnimation, rect);
                        Storyboard.SetTargetProperty(opacityAnimation, "Opacity");

                        opacityAnimation.KeyFrames.Add(
                            new DiscreteDoubleKeyFrame
                            {
                                KeyTime = TimeSpan.Zero,
                                Value = 0
                            });
                        opacityAnimation.KeyFrames.Add(
                            new DiscreteDoubleKeyFrame
                            {
                                KeyTime = TimeSpan.FromSeconds((double)row * RowDelay.TotalSeconds + (double)column * ColumnDelay.TotalSeconds),
                                Value = 0
                            });
                        opacityAnimation.KeyFrames.Add(
                            new EasingDoubleKeyFrame
                            {
                                KeyTime = endKeyTime,
                                EasingFunction = CascadeInEasingFunction,
                                Value = 1
                            });

                        sb.Children.Add(opacityAnimation);

                        //******************** 效果差不错出来了,主要是起始点的设置,还有,这里的动画要不要弄成关键祯?
                        var translateXanimation = new DoubleAnimation();
                        translateXanimation.From = translateXInfo[i];
                        translateXanimation.To = 0;
                        translateXanimation.Duration = endKeyTime;
                        Storyboard.SetTarget(translateXanimation, transfrom);
                        Storyboard.SetTargetProperty(translateXanimation, "TranslateX");
                        sb.Children.Add(translateXanimation);

                        var translateYanimation = new DoubleAnimation();
                        translateYanimation.From = translateYInfo[i];
                        translateYanimation.To = 0;
                        translateYanimation.Duration = endKeyTime;
                        Storyboard.SetTarget(translateYanimation, transfrom);
                        Storyboard.SetTargetProperty(translateYanimation, "TranslateY");
                        sb.Children.Add(translateYanimation);
                    }

                    sb.Begin();
                };
            }
        }
Exemple #26
0
        private void ReplaceCalibrationStick()
        {
            Storyboard sb = new Storyboard();
            KeyTime ktStart = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(0));
            KeyTime ktEnd = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(200));

            DoubleAnimationUsingKeyFrames rotationAnimation = new DoubleAnimationUsingKeyFrames();

            Storyboard.SetTarget(rotationAnimation, rotationTransform);
            Storyboard.SetTargetProperty(rotationAnimation, "(CompositeTransform.Rotation)");

            rotationAnimation.KeyFrames.Add(new EasingDoubleKeyFrame() { KeyTime = ktStart, Value = rotationTransform.Rotation });
            rotationAnimation.KeyFrames.Add(new EasingDoubleKeyFrame() { KeyTime = ktEnd, Value = 135 });

            sb.Children.Add(rotationAnimation);
            sb.Begin();
        }
Exemple #27
0
        private Storyboard GetStoryboard(Image target)
        {
            Storyboard storyboard = new Storyboard();

            if (target.Source != null)
            {
                Storyboard.SetTarget(storyboard, target.RenderTransform);

                var bitmapSource = (Windows.UI.Xaml.Media.Imaging.BitmapSource)(target.Source);

                DoubleAnimationUsingKeyFrames anim;
                QuadraticEase easingFunction = new QuadraticEase() { EasingMode = EasingMode.EaseInOut };
                //if (bitmapSource.PixelHeight > bitmapSource.PixelWidth)
                {

                    anim = new DoubleAnimationUsingKeyFrames();
                    //ANIM on Y
                    var minYValue = 0;
                    var maxYValue = Math.Abs(this.ActualHeight - bitmapSource.PixelHeight);
                    var offset = (this.ActualHeight > maxYValue) ? maxYValue / 2 : 0.0;

                    Storyboard.SetTargetProperty(anim, "TranslateY");
                    anim.AutoReverse = true;
                    anim.RepeatBehavior = RepeatBehavior.Forever;
                    var durationOnY = rnd.Next(9, 19) * Math.Max(maxYValue / 150, 1);

                    anim.KeyFrames.Add(new EasingDoubleKeyFrame() { KeyTime = TimeSpan.FromSeconds(0), Value = minYValue + offset, EasingFunction = easingFunction });
                    anim.KeyFrames.Add(new EasingDoubleKeyFrame() { KeyTime = TimeSpan.FromSeconds(durationOnY), Value = -maxYValue + offset, EasingFunction = easingFunction });
                    anim.KeyFrames.Add(new EasingDoubleKeyFrame() { KeyTime = TimeSpan.FromSeconds(durationOnY * 2), Value = minYValue + offset, EasingFunction = easingFunction });

                    storyboard.Children.Add(anim);

                }

                //if (bitmapSource.PixelWidth > bitmapSource.PixelHeight)
                {

                    var minXValue = 0;

                    var maxXValue = Math.Abs(this.ActualWidth - bitmapSource.PixelWidth);
                    var offsetX = (this.ActualWidth > bitmapSource.PixelWidth) ? maxXValue / 2 : 0.0;

                    anim = new DoubleAnimationUsingKeyFrames();
                    Storyboard.SetTargetProperty(anim, "TranslateX");
                    anim.AutoReverse = true;
                    anim.RepeatBehavior = RepeatBehavior.Forever;
                    var durationOnX = rnd.Next(9, 19) * Math.Max(1, maxXValue / 150);
                    easingFunction = new QuadraticEase() { EasingMode = EasingMode.EaseInOut };
                    anim.KeyFrames.Add(new EasingDoubleKeyFrame() { KeyTime = TimeSpan.FromSeconds(0), Value = minXValue + offsetX, EasingFunction = easingFunction });
                    anim.KeyFrames.Add(new EasingDoubleKeyFrame() { KeyTime = TimeSpan.FromSeconds(durationOnX), Value = -maxXValue + offsetX, EasingFunction = easingFunction });
                    anim.KeyFrames.Add(new EasingDoubleKeyFrame() { KeyTime = TimeSpan.FromSeconds(durationOnX * 2), Value = minXValue, EasingFunction = easingFunction });
                    storyboard.Children.Add(anim);
                }
            }

            return storyboard;
        }
 private void ResetNorth( )
 {
     Storyboard sb = new Storyboard();
     sb.Duration = TimeSpan.FromMilliseconds(500.0);
     DoubleAnimationUsingKeyFrames frames= new DoubleAnimationUsingKeyFrames();
     SplineDoubleKeyFrame frame2 = new SplineDoubleKeyFrame();
     frame2.KeyTime = sb.Duration.TimeSpan;
     frame2.Value = 0.0;
     KeySpline spline = new KeySpline();
     spline.ControlPoint1 = new Point(0.0 , 0.1);
     spline.ControlPoint2 = new Point(0.1 , 1.0);
     frame2.KeySpline = spline;
     SplineDoubleKeyFrame frame = frame2;
     frames.KeyFrames.Add(frame);
     if (this.Map.Angle > 180)
     {
         frame.Value = 360.0;
     }//正转到北
     if (this.Map.Angle <= 180)
     {
         frame.Value = 0.0;
     }//转回去
     frames.SetValue(Storyboard.TargetPropertyProperty , "Angle");
     sb.Children.Add(frames);
     Storyboard.SetTarget(frames , this.Map);
     sb.Begin();
 }
        /// <summary>
        /// Begins the cascading transition asynchronously (waits for it to complete).
        /// </summary>
        /// <returns></returns>
        public async Task BeginCascadingTransitionAsync()
        {
            var transparentBrush =
                new SolidColorBrush(Colors.Transparent);
            LayoutRoot.Children.Clear();

            var totalDelay = TimeSpan.FromSeconds(0);

            var cascadeStoryboard = new Storyboard();

            var previousCharacterRect = new Rect(-100000,0,0,0);

            for (int i = 0; i < Text.Length; )
            {
                int j = 1;

                while (
                    i + j < Text.Length &&
                    Text[i + j] == ' ')
                {
                    j++;
                }

                var tt = new TranslateTransform();

                if (CascadeIn)
                {
                    tt.Y = FromVerticalOffset;
                }

                TextBlock tb = CreateTextBlock(tt);

                if (i > 0)
                {
                    tb.Inlines.Add(
                        new Run
                        {
                            Text = Text.Substring(0, i),
                            Foreground = transparentBrush
                        });
                }
                
                var singleLetterRun = new Run { Text = Text.Substring(i, j) };
                tb.Inlines.Add(singleLetterRun);
                //.GetPositionAtOffset(1, LogicalDirection.Backward)

                if (i + j < Text.Length)
                {
                    tb.Inlines.Add(
                        new Run
                        {
                            Text = Text.Substring(i + j),
                            Foreground = transparentBrush
                        });
                }

                LayoutRoot.Children.Add(tb);

                DoubleAnimationUsingKeyFrames opacityAnimation = null;

                if (UseFade)
                {
                    opacityAnimation = new DoubleAnimationUsingKeyFrames();

                    if (CascadeIn)
                        tb.Opacity = 0;

                    Storyboard.SetTarget(opacityAnimation, tb);
                    Storyboard.SetTargetProperty(opacityAnimation, "UIElement.Opacity");
                    cascadeStoryboard.Children.Add(opacityAnimation);
                }

                DoubleAnimationUsingKeyFrames yAnimation = null;

                if (CascadeIn || CascadeOut)
                {
                    yAnimation = new DoubleAnimationUsingKeyFrames();
                    Storyboard.SetTarget(yAnimation, tt);
                    Storyboard.SetTargetProperty(yAnimation, "TranslateTransform.Y");
                    cascadeStoryboard.Children.Add(yAnimation);
                }

                DoubleAnimationUsingKeyFrames rotationAnimation = null;
                PlaneProjection planeProjection = null;

                if (UseRotation)
                {
                    await tb.WaitForNonZeroSizeAsync();
                    //await Task.Delay(100);

                    var aw = tb.ActualWidth;
                    var ah = tb.ActualHeight;

                    var characterRect = tb.GetCharacterRect(i);
                    tb.Projection = planeProjection = new PlaneProjection();
                    planeProjection.CenterOfRotationX = (characterRect.X + (characterRect.Width / 2)) / aw;
                    
                    if (CascadeIn)
                        planeProjection.RotationY = FromRotation;

                    //var pointer = tb.ContentStart.GetPositionAtOffset(offset, LogicalDirection.Forward);
                    //var rect = pointer.GetCharacterRect(LogicalDirection.Forward);

                    //while (
                    //    rect == previousCharacterRect ||
                    //    rect.X - previousCharacterRect.X < 4)
                    //{
                    //    offset++;
                    //    if (offset > tb.ContentEnd.Offset)
                    //        break;
                    //    pointer = tb.ContentStart.GetPositionAtOffset(offset, LogicalDirection.Forward);
                    //    rect = pointer.GetCharacterRect(LogicalDirection.Forward);
                    //}

                    //previousCharacterRect = rect;

                    //var x = rect.X;
                    //var y = rect.Y;
                    //var w = rect.Width;
                    //var h = rect.Height;

                    //tb.Projection = planeProjection = new PlaneProjection();
                    //planeProjection.CenterOfRotationX = (x + (w / 2)) / aw;
                    //planeProjection.RotationY = FromRotation;

                    //if (!headerPrinted)
                    //{
                    //    Debug.WriteLine("ActualWidth: {0}", aw);
                    //    Debug.WriteLine("ActualHeight: {0}\r\n", ah);
                    //    Debug.WriteLine("po\ti\tj\tx\ty\tw\th\tpx");
                    //    headerPrinted = true;
                    //}

                    //Debug.WriteLine(
                    //    "{0:F0}\t{1:F0}\t{2:F0}\t{3:F0}\t{4:F0}\t{5:F0}\t{6:F0}\t{7:F3}",
                    //    pointer.Offset, i, j, x, y, w, h, planeProjection.CenterOfRotationX);

                    rotationAnimation = new DoubleAnimationUsingKeyFrames();
                    Storyboard.SetTarget(rotationAnimation, planeProjection);
                    Storyboard.SetTargetProperty(rotationAnimation, "PlaneProjection.RotationY");
                    cascadeStoryboard.Children.Add(rotationAnimation);

                    if (CascadeIn)
                    {
                        rotationAnimation.KeyFrames.Add(
                            new DiscreteDoubleKeyFrame
                            {
                                KeyTime = totalDelay,
                                Value = FromRotation
                            });
                        rotationAnimation.KeyFrames.Add(
                            new EasingDoubleKeyFrame
                            {
                                KeyTime = totalDelay + CascadeInDuration,
                                EasingFunction = CascadeInEasingFunction,
                                Value = 0
                            });
                    }

                    if (CascadeOut)
                    {
                        rotationAnimation.KeyFrames.Add(
                            new DiscreteDoubleKeyFrame
                            {
                                KeyTime = totalDelay + (CascadeIn ? CascadeInDuration : TimeSpan.Zero) + HoldDuration,
                                Value = 0
                            });
                        rotationAnimation.KeyFrames.Add(
                            new EasingDoubleKeyFrame
                            {
                                KeyTime = totalDelay + (CascadeIn ? CascadeInDuration : TimeSpan.Zero) + HoldDuration + CascadeOutDuration,
                                EasingFunction = CascadeOutEasingFunction,
                                Value = ToRotation
                            });
                    }
                }

                if (CascadeIn)
                {
                    yAnimation.KeyFrames.Add(
                        new DiscreteDoubleKeyFrame
                        {
                            KeyTime = totalDelay,
                            Value = FromVerticalOffset
                        });
                    yAnimation.KeyFrames.Add(
                        new EasingDoubleKeyFrame
                        {
                            KeyTime = totalDelay + CascadeInDuration,
                            EasingFunction = CascadeInEasingFunction,
                            Value = 0
                        });

                    if (UseFade)
                    {
                        opacityAnimation.KeyFrames.Add(
                            new DiscreteDoubleKeyFrame
                            {
                                KeyTime = totalDelay,
                                Value = 0
                            });
                        opacityAnimation.KeyFrames.Add(
                            new EasingDoubleKeyFrame
                            {
                                KeyTime = totalDelay + CascadeInDuration,
                                EasingFunction = FadeInEasingFunction,
                                Value = 1.0
                            });
                    }
                }

                if (CascadeOut)
                {
                    yAnimation.KeyFrames.Add(
                        new DiscreteDoubleKeyFrame
                        {
                            KeyTime = totalDelay + (CascadeIn ? CascadeInDuration : TimeSpan.Zero) + HoldDuration,
                            Value = 0
                        });
                    yAnimation.KeyFrames.Add(
                        new EasingDoubleKeyFrame
                        {
                            KeyTime = totalDelay + (CascadeIn ? CascadeInDuration : TimeSpan.Zero) + HoldDuration + CascadeOutDuration,
                            EasingFunction = CascadeOutEasingFunction,
                            Value = ToVerticalOffset
                        });

                    if (UseFade)
                    {
                        opacityAnimation.KeyFrames.Add(
                            new DiscreteDoubleKeyFrame
                            {
                                KeyTime = totalDelay + (CascadeIn ? CascadeInDuration : TimeSpan.Zero) + HoldDuration,
                                Value = 1.00
                            });
                        opacityAnimation.KeyFrames.Add(
                            new EasingDoubleKeyFrame
                            {
                                KeyTime = totalDelay + (CascadeIn ? CascadeInDuration : TimeSpan.Zero) + HoldDuration + CascadeOutDuration,
                                EasingFunction = FadeOutEasingFunction,
                                Value = 0.0
                            });
                    }
                }

                totalDelay += CascadeInterval;
                i += j;
            }

            EventHandler<object> eh = null;
            eh = (s, e) =>
            {
                cascadeStoryboard.Completed -= eh;
                //LayoutRoot.Children.Clear();
                //var tb2 = CreateTextBlock(null);
                //tb2.Text = Text;
                //LayoutRoot.Children.Add(tb2);

#if CascadingTextBlock_REPEATFOREVER
                BeginCascadingTransition();
#else
                if (CascadeCompleted != null)
                    CascadeCompleted(this, EventArgs.Empty);
#endif
            };

            cascadeStoryboard.Completed += eh;
            await Task.Delay(StartDelay);
            await cascadeStoryboard.BeginAsync();
        }
        public override void PlayReverse(Action completed)
        {
            var storyboard = new Storyboard();
            var toPage = ToPage;
            var scaleTransform = new ScaleTransform
            {
                CenterX = ToPage.ActualWidth/2,
                CenterY = ToPage.ActualHeight/2,
                ScaleX = 1,
                ScaleY = 1
            };
            toPage.RenderTransform = scaleTransform;
            ToPage.Opacity = 1;
            storyboard.Duration = new Duration(TimeSpan.FromSeconds(0.15));
            var doubleAnimationUsingKeyFrame = new DoubleAnimationUsingKeyFrames
            {
                RepeatBehavior = new RepeatBehavior(TimeSpan.FromSeconds(1)),
                FillBehavior = FillBehavior.HoldEnd
            };
            var doubleAnimationUsingKeyFrame1 = doubleAnimationUsingKeyFrame;
            var keyFrames = doubleAnimationUsingKeyFrame1.KeyFrames;
            var easingDoubleKeyFrame = new EasingDoubleKeyFrame
            {
                KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)),
                Value = 1,
                EasingFunction = new CubicEase()
            };
            keyFrames.Add(easingDoubleKeyFrame);
            var doubleKeyFrameCollection = doubleAnimationUsingKeyFrame1.KeyFrames;
            var easingDoubleKeyFrame1 = new EasingDoubleKeyFrame
            {
                KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.15)),
                Value = 1.4,
                EasingFunction = new CubicEase()
            };
            doubleKeyFrameCollection.Add(easingDoubleKeyFrame1);
            Storyboard.SetTarget(doubleAnimationUsingKeyFrame1, ToPage);
            Storyboard.SetTargetProperty(doubleAnimationUsingKeyFrame1,
                "(UIElement.RenderTransform).(CompositeTransform.ScaleX)");
            storyboard.Children.Add(doubleAnimationUsingKeyFrame1);
            var doubleAnimationUsingKeyFrame2 = new DoubleAnimationUsingKeyFrames
            {
                RepeatBehavior = new RepeatBehavior(TimeSpan.FromSeconds(1)),
                FillBehavior = FillBehavior.HoldEnd
            };
            var doubleAnimationUsingKeyFrame3 = doubleAnimationUsingKeyFrame2;
            var keyFrames1 = doubleAnimationUsingKeyFrame3.KeyFrames;
            var easingDoubleKeyFrame2 = new EasingDoubleKeyFrame
            {
                KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)),
                Value = 1,
                EasingFunction = new CubicEase()
            };
            keyFrames1.Add(easingDoubleKeyFrame2);
            var doubleKeyFrameCollection1 = doubleAnimationUsingKeyFrame3.KeyFrames;
            var easingDoubleKeyFrame3 = new EasingDoubleKeyFrame
            {
                KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.15)),
                Value = 1.4,
                EasingFunction = new CubicEase()
            };
            doubleKeyFrameCollection1.Add(easingDoubleKeyFrame3);
            Storyboard.SetTarget(doubleAnimationUsingKeyFrame3, ToPage);
            Storyboard.SetTargetProperty(doubleAnimationUsingKeyFrame3,
                "(UIElement.RenderTransform).(CompositeTransform.ScaleY)");
            storyboard.Children.Add(doubleAnimationUsingKeyFrame3);
            var doubleAnimationUsingKeyFrame4 = new DoubleAnimationUsingKeyFrames
            {
                RepeatBehavior = new RepeatBehavior(TimeSpan.FromSeconds(1)),
                FillBehavior = FillBehavior.HoldEnd
            };
            var doubleAnimationUsingKeyFrame5 = doubleAnimationUsingKeyFrame4;
            var keyFrames2 = doubleAnimationUsingKeyFrame5.KeyFrames;
            var easingDoubleKeyFrame4 = new EasingDoubleKeyFrame
            {
                KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)),
                Value = 1,
                EasingFunction = new CubicEase()
            };
            keyFrames2.Add(easingDoubleKeyFrame4);
            var doubleKeyFrameCollection2 = doubleAnimationUsingKeyFrame5.KeyFrames;
            var easingDoubleKeyFrame5 = new EasingDoubleKeyFrame
            {
                KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.15)),
                Value = 0,
                EasingFunction = new CubicEase()
            };
            doubleKeyFrameCollection2.Add(easingDoubleKeyFrame5);
            Storyboard.SetTarget(doubleAnimationUsingKeyFrame5, ToPage);
            Storyboard.SetTargetProperty(doubleAnimationUsingKeyFrame5, "(UIElement.Opacity)");
            storyboard.Children.Add(doubleAnimationUsingKeyFrame5);
            var fromPage = FromPage;
            var scaleTransform1 = new ScaleTransform
            {
                CenterX = FromPage.ActualWidth/2,
                CenterY = FromPage.ActualHeight/2,
                ScaleX = 1,
                ScaleY = 1
            };
            fromPage.RenderTransform = scaleTransform1;
            FromPage.Opacity = 1;
            var doubleAnimationUsingKeyFrame6 = new DoubleAnimationUsingKeyFrames
            {
                RepeatBehavior = new RepeatBehavior(TimeSpan.FromSeconds(1)),
                FillBehavior = FillBehavior.HoldEnd
            };
            var doubleAnimationUsingKeyFrame7 = doubleAnimationUsingKeyFrame6;
            var keyFrames3 = doubleAnimationUsingKeyFrame7.KeyFrames;
            var easingDoubleKeyFrame6 = new EasingDoubleKeyFrame
            {
                KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)),
                Value = 0.3,
                EasingFunction = new SineEase()
            };
            keyFrames3.Add(easingDoubleKeyFrame6);
            var doubleKeyFrameCollection3 = doubleAnimationUsingKeyFrame7.KeyFrames;
            var easingDoubleKeyFrame7 = new EasingDoubleKeyFrame
            {
                KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.15)),
                Value = 1,
                EasingFunction = new SineEase()
            };
            doubleKeyFrameCollection3.Add(easingDoubleKeyFrame7);
            Storyboard.SetTarget(doubleAnimationUsingKeyFrame7, FromPage);
            Storyboard.SetTargetProperty(doubleAnimationUsingKeyFrame7,
                "(UIElement.RenderTransform).(CompositeTransform.ScaleX)");
            storyboard.Children.Add(doubleAnimationUsingKeyFrame7);
            var doubleAnimationUsingKeyFrame8 = new DoubleAnimationUsingKeyFrames
            {
                RepeatBehavior = new RepeatBehavior(TimeSpan.FromSeconds(1)),
                FillBehavior = FillBehavior.HoldEnd
            };
            var doubleAnimationUsingKeyFrame9 = doubleAnimationUsingKeyFrame8;
            var keyFrames4 = doubleAnimationUsingKeyFrame9.KeyFrames;
            var easingDoubleKeyFrame8 = new EasingDoubleKeyFrame
            {
                KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)),
                Value = 0.3,
                EasingFunction = new SineEase()
            };
            keyFrames4.Add(easingDoubleKeyFrame8);
            var doubleKeyFrameCollection4 = doubleAnimationUsingKeyFrame9.KeyFrames;
            var easingDoubleKeyFrame9 = new EasingDoubleKeyFrame
            {
                KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.15)),
                Value = 1,
                EasingFunction = new SineEase()
            };
            doubleKeyFrameCollection4.Add(easingDoubleKeyFrame9);
            Storyboard.SetTarget(doubleAnimationUsingKeyFrame9, FromPage);
            Storyboard.SetTargetProperty(doubleAnimationUsingKeyFrame9,
                "(UIElement.RenderTransform).(CompositeTransform.ScaleY)");
            storyboard.Children.Add(doubleAnimationUsingKeyFrame9);
            var doubleAnimationUsingKeyFrame10 = new DoubleAnimationUsingKeyFrames
            {
                RepeatBehavior = new RepeatBehavior(TimeSpan.FromSeconds(1)),
                FillBehavior = FillBehavior.HoldEnd
            };
            var doubleAnimationUsingKeyFrame11 = doubleAnimationUsingKeyFrame10;
            var keyFrames5 = doubleAnimationUsingKeyFrame11.KeyFrames;
            var easingDoubleKeyFrame10 = new EasingDoubleKeyFrame
            {
                KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)),
                Value = 0,
                EasingFunction = new SineEase()
            };
            keyFrames5.Add(easingDoubleKeyFrame10);
            var doubleKeyFrameCollection5 = doubleAnimationUsingKeyFrame11.KeyFrames;
            var easingDoubleKeyFrame11 = new EasingDoubleKeyFrame
            {
                KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.15)),
                Value = 1,
                EasingFunction = new SineEase()
            };
            doubleKeyFrameCollection5.Add(easingDoubleKeyFrame11);
            Storyboard.SetTarget(doubleAnimationUsingKeyFrame11, FromPage);
            Storyboard.SetTargetProperty(doubleAnimationUsingKeyFrame11, "(UIElement.Opacity)");
            storyboard.Children.Add(doubleAnimationUsingKeyFrame11);

            try
            {
                storyboard.Begin();
                if (completed != null)
                {
                    completed.Invoke();
                }
            }
            catch
            {
                base.Play(completed);
            }
        }