StopStoryboard 不...停止 BeginStoryboard
我从我的项目中提取了这段代码,因为我试图找到我犯的一个错误,该错误使我的 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>
自己尝试一下代码,第一个按钮触发故事板,第二个按钮应该停止它,但没有任何反应,所以第一个按钮中的动画愉快地进行。
I have extracted this piece of code from my project, because I was trying to find a mistake I made which keeps my BeginStoryboard
from stopping itself. I simplified code as much as possible and still I don't see a problem. What do you think it could be?
<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>
Try the code yourself, first Button triggers the storyboard, second one is supposed to stop it, but nothing happens, so animation in first Button goes on happily.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的
BeginStoryboard
位于不同的命名范围中,因此StopStoryboard
看不到它。您需要将两个触发器放在同一个集合中,例如 MSDN 示例。
Your
BeginStoryboard
is in a different naming scope, so theStopStoryboard
doesn't see it.You need to put both triggers in the same collection, like the MSDN example.