[英]How do I start an animation by means of ButtonClick event?
I have some challenges with a code as follows. 我的代码有一些挑战,如下所示。 I need to start this simpliest animation code by means of eg ButtonClick event or a method in Code Behind.
我需要通过例如ButtonClick事件或Code Behind中的方法来启动这个最简单的动画代码。 Could anyone shed the light on this matter?
谁能阐明这个问题?
Update: The code itself is working perfectly. 更新:代码本身运行正常。 I need just start it by a button.
我只需要按一下按钮即可。 Not while window loading.
加载窗口时不这样做。
Thanks in advance! 提前致谢!
<StackPanel>
<Button x:Name="Button" Content="Start" Click="Button_Click"/>
</StackPanel>
<Image
Name="img"
Width="128"
Height="128">
<Image.Triggers>
<EventTrigger RoutedEvent="Loaded">
<BeginStoryboard>
<Storyboard RepeatBehavior="Forever">
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Source" Duration="0:0:2.0">
<DiscreteObjectKeyFrame KeyTime="0:0:0">
<DiscreteObjectKeyFrame.Value>
<BitmapImage UriSource="D://Speakers//Wave_00.png" />
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
<DiscreteObjectKeyFrame KeyTime="0:0:.5">
<DiscreteObjectKeyFrame.Value>
<BitmapImage UriSource="D://Speakers//Wave_01.png" />
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
<DiscreteObjectKeyFrame KeyTime="0:0:1">
<DiscreteObjectKeyFrame.Value>
<BitmapImage UriSource="D://Speakers//Wave_02.png" />
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
<DiscreteObjectKeyFrame KeyTime="0:0:1.5">
<DiscreteObjectKeyFrame.Value>
<BitmapImage UriSource="D://Speakers//Wave_03.png" />
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Image.Triggers>
</Image>
</Grid>
try to change 尝试改变
eventtrigger routedevent="loaded" eventtrigger routedevent =“ loaded”
in 在
EventTrigger RoutedEvent="Button_Click" EventTrigger RoutedEvent =“ Button_Click”
i hope it works 我希望它能起作用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.