コード例 #1
0
        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;
                    //projection.CenterOfRotationX = projection.CenterOfRotationZ = 0;
                    //projection.GlobalOffsetX = column;
                    //projection.GlobalOffsetY = row;
                    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;

                        //var transform = rects[i].Projection as PlaneProjection;
                        //transform.GlobalOffsetX = transform.GlobalOffsetX * RW;
                        //transform.GlobalOffsetY = transform.GlobalOffsetY * 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的效果可以研究下如何加比较好
                        var rotationAnimationY = new DoubleAnimationUsingKeyFrames();
                        Storyboard.SetTarget(rotationAnimationY, projection);
                        Storyboard.SetTargetProperty(rotationAnimationY, "RotationY");

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

                        sb.Children.Add(rotationAnimationY);

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

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

                        sb.Children.Add(rotationAnimationZ);
                        //****************************

                        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.From     = transfrom.TranslateX;
                        translateXanimation.To       = 0;
                        translateXanimation.Duration = endKeyTime;
                        //translateXanimation.EasingFunction = CascadeInEasingFunction;
                        //BackEase(缓动函数) BounceEase(弹跳效果) CircleEase(加速和/或减速) CubicEase( f(t) = t3 创建加速和/或减速)
                        //ElasticEase(弹簧来回振动直到停止) ExponentialEase(指数公式创建加速和/或减速) PowerEase(f(t) = tp 创建加速和/或减速)
                        //QuadraticEase(f(t) = t2 创建加速和/或减速) QuarticEase(f(t) = t4 创建加速和/或减速) QuinticEase(f(t) = t5 创建加速和/或减速)
                        //SineEase(正弦方程式(见下面的备注)创建加速和/或减速)
                        Storyboard.SetTarget(translateXanimation, transfrom);
                        Storyboard.SetTargetProperty(translateXanimation, "TranslateX");
                        sb.Children.Add(translateXanimation);

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

                        var globalOffsetY = new DoubleAnimationUsingKeyFrames();
                        Storyboard.SetTarget(globalOffsetY, projection);
                        Storyboard.SetTargetProperty(globalOffsetY, "GlobalOffsetY");

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

                        //sb.Children.Add(globalOffsetY);

                        var globalOffsetX = new DoubleAnimationUsingKeyFrames();
                        Storyboard.SetTarget(globalOffsetX, projection);
                        Storyboard.SetTargetProperty(globalOffsetX, "GlobalOffsetX");

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

                        //sb.Children.Add(globalOffsetX);
                    }

                    sb.Begin();
                };
            }
        }
コード例 #2
0
        /// <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();
        }
コード例 #3
0
        public async void Cascade()
        {
            RH = RW = double.NaN;
            if (!_isLoaded ||
                _layoutCanvas == null)
            {
                return;
            }

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

            _layoutCanvas.Children.Clear();

            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;

            case ControlLibrary.CascadeDirection.LeftCenter:
            case ControlLibrary.CascadeDirection.RightCenter:
            case ControlLibrary.CascadeDirection.TopCenter:
            case ControlLibrary.CascadeDirection.BottomCenter:
                startColumn        = (Columns - 1) / 2;
                exclusiveEndColumn = Columns / 2;
                columnIncrement    = 0;
                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);

            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);

                    //row代表高Y,column代表宽X
                    rect.Tag = new Point(column, row);
                    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 = projection.CenterOfRotationX = 0.5;
                    projection.RotationX         = 90;
                    rect.Projection = projection;

                    //设置填充图片笔刷矩形的呈现位置
                    var rectTransform = new CompositeTransform();
                    //rectTransform.CenterX = rectTransform.CenterY = 0.5;
                    rectTransform.TranslateX   = column;
                    rectTransform.TranslateY   = this.H;//row;
                    rectTransform.ScaleY       = 1;
                    rect.RenderTransformOrigin = new Windows.Foundation.Point(0.5, 0.5);
                    rect.RenderTransform       = rectTransform;

                    _layoutCanvas.Children.Add(rect);
                }
            }
            GetRHAndRW();
            if (!double.IsNaN(RH) && !double.IsNaN(RW))
            {
                var indices = new List <int>(Rows * Columns);
                for (int i = 0; i < Rows * Columns; i++)

                /*
                 * var indices = new List<int>();
                 * for (int i = 0; i < rects.Count;)
                 */
                {
                    //Canvas.SetLeft(rects[i], ((Point)rects[i].Tag).X * this.RW);
                    //Canvas.SetTop(rects[i], 0);
                    indices.Add(i);
                    rects[i].Width  = this.RW;
                    rects[i].Height = this.RH;
                    rects[i].SetValue(Canvas.LeftProperty, ((Point)rects[i].Tag).X * this.RW);
                    rects[i].SetValue(Canvas.TopProperty, 0);

                    /*
                     * var brush = await GetImageBrush((uint)(((Point)rects[i].Tag).X * this.RW), (uint)(((Point)rects[i].Tag).Y * this.RH), (uint)this.RW, (uint)this.RH);
                     * brush.Stretch = this.Stretch;
                     * rects[i].Fill = brush;
                     */

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

                    /*
                     * i++;
                     */
                }

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

                //for (int ii = 0; ii < indices.Count; ii++)
                for (int ii = 0; ii < indices.Count;)
                {
                    sb = new Storyboard();
                    var i          = indices[ii];
                    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);
                    endKeyTime = TimeSpan.FromSeconds(endKeyTime.TotalSeconds / 3 * 2);

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

                    sb.Children.Add(rotationAnimation);

                    #region RotationY 和 RotationZ 没有加入到动画中(暂时不要)
                    var rotationAnimationY = new DoubleAnimationUsingKeyFrames();
                    Storyboard.SetTarget(rotationAnimationY, projection);
                    Storyboard.SetTargetProperty(rotationAnimationY, "RotationY");

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

                    //sb.Children.Add(rotationAnimationY);

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

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

                    //sb.Children.Add(rotationAnimationZ);
                    #endregion

                    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 = new ElasticEase
                        {
                            EasingMode = EasingMode.EaseOut, Oscillations = 3, Springiness = 0.0
                        },
                        Value = 1
                    });

                    sb.Children.Add(opacityAnimation);

                    //BackEase(缓动函数) BounceEase(弹跳效果) CircleEase(加速和/或减速) CubicEase( f(t) = t3 创建加速和/或减速)
                    //ElasticEase(弹簧来回振动直到停止) ExponentialEase(指数公式创建加速和/或减速) PowerEase(f(t) = tp 创建加速和/或减速)
                    //QuadraticEase(f(t) = t2 创建加速和/或减速) QuarticEase(f(t) = t4 创建加速和/或减速) QuinticEase(f(t) = t5 创建加速和/或减速)
                    //SineEase(正弦方程式(见下面的备注)创建加速和/或减速)
                    var translateXAanimation = new DoubleAnimation();
                    translateXAanimation.From     = transfrom.TranslateX;
                    translateXAanimation.To       = 0;
                    translateXAanimation.Duration = endKeyTime;
                    //translateXAanimation.EasingFunction = CascadeInEasingFunction;
                    Storyboard.SetTarget(translateXAanimation, transfrom);
                    Storyboard.SetTargetProperty(translateXAanimation, "TranslateX");
                    sb.Children.Add(translateXAanimation);

                    /*
                     * //暂且不要
                     * var translateYanimation = new DoubleAnimation();
                     * translateYanimation.From = transfrom.TranslateY;
                     * translateYanimation.To = ((Point)rects[i].Tag).Y * rects[i].Height;
                     * translateYanimation.Duration = endKeyTime;
                     * //translateYanimation.EasingFunction = CascadeInEasingFunction;
                     * Storyboard.SetTarget(translateYanimation, transfrom);
                     * Storyboard.SetTargetProperty(translateYanimation, "TranslateY");
                     * sb.Children.Add(translateYanimation);
                     */

                    /*
                     * //一种形式的动画
                     * var translateYAanimation = new DoubleAnimationUsingKeyFrames();
                     * Storyboard.SetTarget(translateYAanimation, transfrom);
                     * Storyboard.SetTargetProperty(translateYAanimation, "TranslateY");
                     *
                     * translateYAanimation.KeyFrames.Add(
                     *  new DiscreteDoubleKeyFrame
                     *  {
                     *      KeyTime = TimeSpan.Zero,
                     *      Value = transfrom.TranslateY
                     *  });
                     * translateYAanimation.KeyFrames.Add(
                     *  new DiscreteDoubleKeyFrame
                     *  {
                     *      KeyTime = endKeyTime,
                     *      Value = ((Point)rects[i].Tag).Y * rects[i].Height
                     *  });
                     */

                    //另外一种
                    var translateYAanimation = new DoubleAnimationUsingKeyFrames();
                    Storyboard.SetTarget(translateYAanimation, transfrom);
                    Storyboard.SetTargetProperty(translateYAanimation, "TranslateY");

                    translateYAanimation.KeyFrames.Add(
                        new SplineDoubleKeyFrame
                    {
                        KeyTime = TimeSpan.Zero,
                        Value   = transfrom.TranslateY
                    });
                    translateYAanimation.KeyFrames.Add(
                        new SplineDoubleKeyFrame
                    {
                        KeyTime = TimeSpan.FromSeconds(endKeyTime.TotalSeconds / 4 * 3),
                        Value   = ((Point)rects[i].Tag).Y * rects[i].Height / 4 * 3
                    });
                    translateYAanimation.KeyFrames.Add(
                        new EasingDoubleKeyFrame
                    {
                        KeyTime        = endKeyTime,
                        EasingFunction = CascadeInEasingFunction,
                        Value          = ((Point)rects[i].Tag).Y * rects[i].Height
                    });

                    sb.Children.Add(translateYAanimation);

                    var scaleTransformYAanimation = new DoubleAnimationUsingKeyFrames();
                    Storyboard.SetTarget(scaleTransformYAanimation, transfrom);
                    Storyboard.SetTargetProperty(scaleTransformYAanimation, "ScaleY");

                    scaleTransformYAanimation.KeyFrames.Add(
                        new SplineDoubleKeyFrame
                    {
                        KeyTime = TimeSpan.FromSeconds(endKeyTime.TotalSeconds / 4 * 3),
                        Value   = -1
                    });
                    scaleTransformYAanimation.KeyFrames.Add(
                        new SplineDoubleKeyFrame
                    {
                        KeyTime = endKeyTime,
                        Value   = 1
                    });

                    sb.Children.Add(scaleTransformYAanimation);
                    //await sb.BeginAsync();
                    sb.Begin();
                    await Task.Delay(TimeSpan.FromSeconds(endKeyTime.TotalSeconds / 10 * 1));

                    ii++;
                }

                //sb.Begin();
            }
        }
コード例 #4
0
 /// <summary>
 /// 생성자. 관계 연결의 방향이 필요
 /// </summary>
 /// <param name="Direction">관계 연결의 방향</param>
 public CascadeRelationAttribute(CascadeDirection Direction)
 {
     this.Direction = Direction;
     this.Clonable  = true;
 }
コード例 #5
0
        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();

            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;

            case ControlLibrary.CascadeDirection.LeftCenter:
            case ControlLibrary.CascadeDirection.RightCenter:
            case ControlLibrary.CascadeDirection.TopCenter:
            case ControlLibrary.CascadeDirection.BottomCenter:
                startColumn        = (Columns - 1) / 2;
                exclusiveEndColumn = Columns / 2;
                columnIncrement    = 0;
                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);

            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);

                    //row代表高Y,column代表宽X
                    rect.Tag = new Point(column, row);
                    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 = projection.CenterOfRotationX = 0.5;
                    projection.RotationX         = 90;
                    //projection.RotationY = 25;
                    rect.Projection = projection;

                    //设置填充图片笔刷矩形的呈现位置
                    var rectTransform = new CompositeTransform();
                    //rectTransform.CenterX = rectTransform.CenterY = 0.5;
                    rectTransform.TranslateX   = column;
                    rectTransform.TranslateY   = this.H;//row;
                    rectTransform.Rotation     = 0;
                    rect.RenderTransformOrigin = new Windows.Foundation.Point(0.5, 0.5);
                    rect.RenderTransform       = rectTransform;

                    _layoutGrid.Children.Add(rect);
                }
            }
            GetRHAndRW();
            if (!double.IsNaN(RH) && !double.IsNaN(RW))
            {
                var indices = new List <int>(Rows * Columns);

                for (int i = 0; i < Rows * Columns; i++)
                {
                    indices.Add(i);
                    rects[i].Width  = this.RW;
                    rects[i].Height = this.RH;
                    rects[i].HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Left;
                    rects[i].VerticalAlignment   = Windows.UI.Xaml.VerticalAlignment.Top;
                    rects[i].Margin = new Thickness(((Point)rects[i].Tag).X * this.RW, 0, 0, 0);

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

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

                for (int ii = 0; ii < indices.Count; ii++)
                {
                    var i          = indices[ii];
                    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的效果可以研究下如何加比较好
                    var rotationAnimationY = new DoubleAnimationUsingKeyFrames();
                    Storyboard.SetTarget(rotationAnimationY, projection);
                    Storyboard.SetTargetProperty(rotationAnimationY, "RotationY");

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

                    //sb.Children.Add(rotationAnimationY);

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

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

                    //sb.Children.Add(rotationAnimationZ);
                    //****************************

                    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.From     = transfrom.TranslateX;
                    translateXanimation.To       = 0;
                    translateXanimation.Duration = endKeyTime;
                    //translateXanimation.EasingFunction = CascadeInEasingFunction;
                    //BackEase(缓动函数) BounceEase(弹跳效果) CircleEase(加速和/或减速) CubicEase( f(t) = t3 创建加速和/或减速)
                    //ElasticEase(弹簧来回振动直到停止) ExponentialEase(指数公式创建加速和/或减速) PowerEase(f(t) = tp 创建加速和/或减速)
                    //QuadraticEase(f(t) = t2 创建加速和/或减速) QuarticEase(f(t) = t4 创建加速和/或减速) QuinticEase(f(t) = t5 创建加速和/或减速)
                    //SineEase(正弦方程式(见下面的备注)创建加速和/或减速)
                    Storyboard.SetTarget(translateXanimation, transfrom);
                    Storyboard.SetTargetProperty(translateXanimation, "TranslateX");
                    sb.Children.Add(translateXanimation);

                    var translateYanimation = new DoubleAnimation();
                    /*translateYanimation.From = translateYInfo[i];*/
                    translateYanimation.From     = transfrom.TranslateY;
                    translateYanimation.To       = ((Point)rects[i].Tag).Y * rects[i].Height;
                    translateYanimation.Duration = endKeyTime;
                    //translateYanimation.EasingFunction = CascadeInEasingFunction;
                    Storyboard.SetTarget(translateYanimation, transfrom);
                    Storyboard.SetTargetProperty(translateYanimation, "TranslateY");
                    sb.Children.Add(translateYanimation);
                    //****************************
                }

                sb.Begin();
            }
        }