Wpf StopStoryboard没有';T停止起始板
我从我的项目中提取了这段代码,因为我试图找到我犯的一个错误,这个错误使我的Wpf StopStoryboard没有';T停止起始板,wpf,xaml,animation,storyboard,Wpf,Xaml,Animation,Storyboard,我从我的项目中提取了这段代码,因为我试图找到我犯的一个错误,这个错误使我的BeginStoryboard无法自行停止。我尽可能简化了代码,但仍然没有发现问题。你认为可能是什么 <Window Width="640" Height="480" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> <StackPanel> <Button Content="Start" Name="
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>
你自己试试代码,第一个按钮触发故事板,第二个按钮应该停止它,但什么也没有发生,所以第一个按钮中的动画继续愉快地进行。你的
开始故事板
在不同的命名范围内,所以停止故事板
看不到它
您需要将两个触发器放在同一个集合中,例如。Link将打开4.5/4.6.net版本页面,该页面没有示例。切换到4.0以查看一个。