gpt4 book ai didi

c# - WPF中动画运行时如何hold住动画?

转载 作者:行者123 更新时间:2023-11-30 17:49:12 24 4
gpt4 key购买 nike

比如translate transform动画正在运行,我想hold住动画,但又不想停止,怎么办?

最佳答案

为了在动画中暂停正常工作,您需要从代码中调用 Begin() 方法,例如 Loaded 事件处理程序(例如:Window_Loaded),因为- 引自 MSDN :

When you Begin a storyboard that was paused, it appears to resume and restart. However, that is not what actually happens. The Begin method actually replaces itself with an unpaused version. Each time the Begin method is called, clock objects are created for the storyboard. These clocks are distributed to the properties they animate. So, when the Begin method is called again, it does not restart its clocks; it replaces them with new clocks.

例子:

<Window.Resources>
<Storyboard x:Key="SomeStoryboard">
...
</Storyboard>
</Window.Resources>

Loaded 事件或其他事件中:

MyStoryboard = (Storyboard)this.FindResource("SomeStoryboard");
MyStoryboard.Begin();

Pause 按钮中:

private void ButtonPause_Click(object sender, RoutedEventArgs e)
{
MyStoryboard.Pause();
}

更多信息,请查看:

MSDN: Storyboard.Pause Method

关于c# - WPF中动画运行时如何hold住动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22006644/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com