【发布时间】:2011-03-15 08:33:15
【问题描述】:
这看起来应该很容易,但我无法让 WPF 故事板暂停。我调用了 Pause,但没有任何反应——它继续制作动画。
这是一个复制案例:一个按钮,它的宽度动画。如果单击该按钮,它会在情节提要上调用暂停。我希望,一旦我单击按钮,它的宽度应该停止变化;相反,它的宽度保持正确的动画效果,就好像我从未调用过暂停一样。
NameScope.SetNameScope(this, new NameScope());
var storyboard = new Storyboard();
var button = new Button { Content = "Pause", Name = "pause" };
this.Content = button;
RegisterName(button.Name, button);
var animation = new DoubleAnimation(0, 200, TimeSpan.FromSeconds(5));
Storyboard.SetTargetName(animation, button.Name);
Storyboard.SetTargetProperty(animation,
new PropertyPath(FrameworkElement.WidthProperty));
storyboard.Children.Add(animation);
button.Click += (sender, e) => { storyboard.Pause(this); };
storyboard.Begin(this);
根据我对文档的理解,我应该使用传递给Begin 的相同参数调用Pause(FrameworkElement) 重载,因此是上面的Pause(this)。但我也试过storyboard.Pause(),行为没有改变。我还尝试了storyboard.Pause(button),只是为了它,再次没有效果。我会尝试 storyboard.Pause(storyboard) 和 storyboard.Pause(animation) 只是为了用尽可能性,但没有一个编译 - 它想要一个 FrameworkElement(或 FrameworkContentElement)。
如何让故事板暂停?
【问题讨论】:
标签: wpf animation storyboard