gpt4 book ai didi

wpf - StopStoryboard 不会...停止 BeginStoryboard

转载 作者:行者123 更新时间:2023-12-01 18:58:18 24 4
gpt4 key购买 nike

我从我的项目中提取了这段代码,因为我试图找到我犯的一个错误,该错误使我的 BeginStoryboard 无法自行停止。我尽可能地简化了代码,但仍然没有发现问题。你认为它可能是什么?

<Window Width="640" Height="480" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<StackPanel>
<Button Content="Start" Name="Button" Width="200">
<Button.Triggers>
<EventTrigger RoutedEvent="Button.Click">
<BeginStoryboard Name="Storyboard">
<Storyboard>
<DoubleAnimation By="150" Duration="0:0:5" Storyboard.TargetName="Button" Storyboard.TargetProperty="Width"/>
<StringAnimationUsingKeyFrames Storyboard.TargetName="Button" Storyboard.TargetProperty="Content">
<DiscreteStringKeyFrame KeyTime="0:0:5" Value="Did you click? Because I obviously didn't stop..."/>
</StringAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Button.Triggers>
</Button>
<Button Content="Stop">
<Button.Triggers>
<EventTrigger RoutedEvent="Button.Click">
<StopStoryboard BeginStoryboardName="Storyboard"/>
</EventTrigger>
</Button.Triggers>
</Button>
</StackPanel>
</Window>

自己尝试一下代码,第一个按钮触发 Storyboard,第二个按钮应该停止它,但没有任何反应,所以第一个按钮中的动画顺利进行。

最佳答案

您的 BeginStoryboard 位于不同的命名范围内,因此 StopStoryboard 看不到它。

您需要将两个触发器放在同一个集合中,例如 the MSDN example .

关于wpf - StopStoryboard 不会...停止 BeginStoryboard,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7930397/

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