我正在使用故事板创建一个动画,整个东西都在ItemsControl中,当我启动动画启动应用程序时,但是我希望能够在从数据库中收到值时立即停止动画。如何在ItemsControl模板中获取特定的故事板,以便我可以在我的代码后面停止它。或者是否有一个属性,我可以在后面的代码中绑定和使用数据。
目前我的代码看起来像这样
<StackPanel
x:Name="spStart"
Margin="0,10,5,0">
<Image x:Name="Round" Source="Images/Start.png"
Height="35"
Stretch="Uniform"
ToolTipService.ToolTip="Start"
RenderTransformOrigin="0.5,0.5">
<Image.RenderTransform>
<TransformGroup>
<RotateTransform/>
</TransformGroup>
</Image.RenderTransform>
<Image.Triggers>
<EventTrigger RoutedEvent="Grid.Loaded">
<BeginStoryboard>
<Storyboard x:Name="RotatingStory" Completed="myStoryboard_Completed"
x:Uid="{Binding FileReceived}">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Storyboard.TargetName="Round"
Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(RotateTransform.Angle)">
<SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
<SplineDoubleKeyFrame KeyTime="00:00:03" Value="360"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Image.Triggers>
</Image>
</StackPanel>
答案 0 :(得分:1)
查看文档已经尝试过: -
var sb = ((BeginStoryBoard)Round.Triggers[0].Actions[0]).Storyboard;
sb.Stop; // Or whatever else you want to do the storyboard such as SkipToFill.