c# - 如何使用 Storyboard为 Stackpanel 的边距设置动画?

标签 c# wpf silverlight 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();}
                    });

最佳答案

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

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

关于c# - 如何使用 Storyboard为 Stackpanel 的边距设置动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10181245/

相关文章:

c# - DataTemplate 中的 WP7 缩放图像

c# - 我应该考虑从 WPF 切换到 Silverlight 吗?

c# - 对连续元素进行分组并选择第一个和最后一个元素

c# - 在 C# 中检测两个 json 文件之间的差异

c# - 在 C# 中访问 Excel 单元格值

c# - 如何对 CollectionViewSource 的组进行排序

wpf - 避免输出窗口中的绑定(bind)错误

c# - 使用 C# 的 .docx 中的数字签名信息

wpf - DomainCollectionView单元测试

c# - 如何将 Silverlight UI 绑定(bind)到 .NET 类