如何使用情节提要为 Stackpanel 的边距设置动画?

use*_*388 2 c# silverlight wpf windows-phone-7

我想使用它,但它不起作用,我想在代码后面创建一个平铺动画,或者如果你知道这个 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();}
                    });
Run Code Online (Sandbox Code Playgroud)

LPL*_*LPL 5

使用 aThicknessAnimation代替DoubleAnimation. 几乎是一样的。

编辑:

如果你想让动画无穷无尽地使用Timeline.RepeatBehavior

myThicknessAnimation1.RepeatBehavior = RepeatBehavior.Forever;
Run Code Online (Sandbox Code Playgroud)


zvi*_*iad 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);
Run Code Online (Sandbox Code Playgroud)