Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用AnimationPoint(windows phone)设置矩形动画?_C#_Windows Phone 7_Animation_Rectangles - Fatal编程技术网

C# 如何使用AnimationPoint(windows phone)设置矩形动画?

C# 如何使用AnimationPoint(windows phone)设置矩形动画?,c#,windows-phone-7,animation,rectangles,C#,Windows Phone 7,Animation,Rectangles,我想使用AnimationPoint设置重角动画。 我怎么做? 附笔。 我在谷歌搜索,但没有找到我需要的。 我试试这个: private void drawRect() { var d = new Grid(); var moveTranc = new TranslateTransform() { X = 1,Y = 1 }; var e2 = new Rectangle() { Stroke

我想使用AnimationPoint设置重角动画。 我怎么做? 附笔。 我在谷歌搜索,但没有找到我需要的。 我试试这个:

 private void drawRect()
    {
        var d = new Grid();

        var moveTranc = new TranslateTransform() { X = 1,Y = 1 };

        var e2 = new Rectangle()
        {
            Stroke = new SolidColorBrush(System.Windows.Media.Color.FromArgb(255, 0, 200, 0)),
            RenderTransform = moveTranc,
            RadiusX = 100,
            RadiusY = 100,
            RenderTransformOrigin = new Point(0.5f,0.5f),
        };
        var pointAnimation = new PointAnimation()
        {
            Duration = new Duration(TimeSpan.FromSeconds(2)),
            From = new Point(e2.RadiusX,e2.RadiusY),
            To = new Point(450,450)
        };
        var storyBoard = new Storyboard();
         storyBoard.RepeatBehavior = RepeatBehavior.Forever;
         storyBoard.Children.Add(pointAnimation);

         Storyboard.SetTarget(pointAnimation, e2);
         Storyboard.SetTargetProperty(pointAnimation, new PropertyPath("(UIElement.RenderTransform).(TranslateTransform.X).(TranslateTransform.Y)"));
        d.Children.Add(e2);
        ContentPanel.Children.Add(d);
        storyBoard.Begin();
    }

我发现了使用双动画制作矩形动画的任何变体

        Rectangle myRectangle;
        Storyboard sb;

        //creating rectangle
        myRectangle = new Rectangle();
        myRectangle.Width = 200;
        myRectangle.Height = 200;
        Color myColor = Color.FromArgb(255, 255, 0, 0);
        SolidColorBrush myBrush = new SolidColorBrush();
        myBrush.Color = myColor;
        myRectangle.Fill = myBrush;

        // Create the transform
        TranslateTransform moveTransform = new TranslateTransform();
        moveTransform.X = 0;
        moveTransform.Y = 0;
        myRectangle.RenderTransform = moveTransform;


        // Add the rectangle to the tree.
        if (!LayoutRoot.Children.Contains(myRectangle))    LayoutRoot.Children.Add(myRectangle);
        // Create a duration of 2 seconds.
        Duration duration = new Duration(TimeSpan.FromSeconds(1.0));
        // Create two DoubleAnimations and set their properties.
        DoubleAnimation myDoubleAnimationX = new DoubleAnimation();
        sb = new Storyboard();
        sb.Duration = duration;
        sb.Children.Add(myDoubleAnimationX);
        Storyboard.SetTarget(myDoubleAnimationX, moveTransform);
        Storyboard.SetTargetProperty(myDoubleAnimationX, new PropertyPath("X"));

        DoubleAnimation myDoubleAnimationY = new DoubleAnimation();
        sb.Children.Add(myDoubleAnimationY);
        Storyboard.SetTarget(myDoubleAnimationY, moveTransform);
        Storyboard.SetTargetProperty(myDoubleAnimationY, new PropertyPath("Y"));

        myDoubleAnimationX.To = 0;
        myDoubleAnimationX.From = 340;
        myDoubleAnimationY.To = 0;
        myDoubleAnimationY.From = 340;
        // Make the Storyboard a resource.
        if (!LayoutRoot.Resources.Contains("unique_id"))      LayoutRoot.Resources.Add("unique_id", sb);
        sb.Begin();

你看过TranslateTransform的动画制作吗。这是更常见的移动方式。