2

我想使用它,但它不起作用,我想在代码后面创建一个平铺动画,或者如果你知道这个 gol 的项目,请写信给我

 Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        while(true){
                        Duration duration = new Duration(TimeSpan.FromSeconds(0.15));

                        // Create two DoubleAnimations and set their properties.
                        DoubleAnimation myDoubleAnimation1 = new DoubleAnimation();

                        myDoubleAnimation1.Duration = duration;
                        myDoubleAnimation1.From = -173
                        myDoubleAnimation1.To = 173;
                        Storyboard sb = new Storyboard();
                        sb.Duration = duration;

                        sb.Children.Add(myDoubleAnimation1);

                        Storyboard.SetTarget(myDoubleAnimation1, image);

                        // Set the attached properties of Canvas.Left and Canvas.Top
                        // to be the target properties of the two respective DoubleAnimations.
                        Storyboard.SetTargetProperty(myDoubleAnimation1, new PropertyPath(StackPanel.MarginProperty));

                        // Begin the animation.
                        sb.Begin();}
                    });
4

2 回答 2

5

使用 aThicknessAnimation而不是 a DoubleAnimation。这几乎是一样的。

编辑:

如果你想让Animation没完没了的使用Timeline.RepeatBehavior

myThicknessAnimation1.RepeatBehavior = RepeatBehavior.Forever;
于 2012-04-16T20:45:02.007 回答
5

如果有人需要,这是工作示例:

//Animate margin for Label, named "label" from right to left. from 300 to 0.

var sb = new Storyboard();
var ta = new ThicknessAnimation();
ta.BeginTime = new TimeSpan(0);
ta.SetValue(Storyboard.TargetNameProperty, "label");
Storyboard.SetTargetProperty(ta, new PropertyPath(MarginProperty));

ta.From = new Thickness(300, 30, 0, 0);
ta.To = new Thickness(0, 30, 0, 0);
ta.Duration = new Duration(TimeSpan.FromSeconds(3));

sb.Children.Add(ta);
sb.Begin(this);
于 2016-11-12T08:15:16.263 回答