我怎样才能暂停故事板? [英] How can I pause a storyboard?
问题描述
这似乎应该是一个没有脑子,但我不能让一个WPF故事板暂停。我叫暂停,并没有任何反应 - 它保持正常动画
This seems like it should be a no-brainer, but I can't get a WPF storyboard to pause. I call Pause and nothing happens -- it keeps right on animating.
下面是一个摄制情况:该动画的宽度按钮。如果您按一下按钮,它调用暂停的故事板。我希望的是,当我按一下按钮,其宽度应不再变化;而不是它的宽度保持正常动画,就好像我从来没有叫暂停。
Here's a repro case: a button that animates its width. If you click the button, it calls Pause on the storyboard. I would expect that, as soon as I click the button, its width should stop changing; instead its width keeps right on animating as if I never called 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);
据我了解的文档,我应该叫暂停(FrameworkElement的)与我传递给
,因此,相同的参数
超载开始暂停(本)
。但我也试过 storyboard.Pause()
,与任何变化。我也试过 storyboard.Pause(按钮)
只是它的挫折感,再次没有影响。我曾尝试 storyboard.Pause(故事板)
和 storyboard.Pause(动画)
只是用尽的可能性,但没有一个编译 - 它想要一个FrameworkElement的(或FrameworkContentElement上)
From what I understand of the docs, I should call the Pause(FrameworkElement)
overload with the same parameter I passed to Begin
, hence the Pause(this)
above. But I've also tried storyboard.Pause()
, with no change in behavior. I also tried storyboard.Pause(button)
just for the heck of it, again with no effect. I would have tried storyboard.Pause(storyboard)
and storyboard.Pause(animation)
just to exhaust the possibilities, but neither one compiles -- it wants a FrameworkElement (or FrameworkContentElement).
我如何获得storyboad暂停?
How do I get the storyboad to pause?
推荐答案
我不知道为什么你正在使用weired SetNameScope等清除您的code,我可以让它工作:
I don't know why you are using that weired SetNameScope etc. Clearing your code i could make it work:
//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.SetTarget(animation, button);
Storyboard.SetTargetProperty(animation,
new PropertyPath(FrameworkElement.WidthProperty));
storyboard.Children.Add(animation);
button.Click += (sender, e) => { storyboard.Pause(); };
storyboard.Begin();
这篇关于我怎样才能暂停故事板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!