我正在使用两个故事板向左和向右移动球(图像),在左键的点击事件中我想向左移动球,在右键的点击事件中,球应该向右移动。它在点击左右按钮时可以正常工作,但在加载应用程序故事板时会自动开始,并且球会在不点击按钮的情况下移动一步。如何限制情节提要自动开始?
这是我第一个将球向左移动 40 像素的故事板:
<EventTrigger>
<BeginStoryboard>
<Storyboard x:Name="ballstoryleft">
<DoubleAnimation Storyboard.TargetName="balltrans" Storyboard.TargetProperty="TranslateX"
Duration="0:0:0.5" By="-40" FillBehavior="HoldEnd">
<DoubleAnimation.EasingFunction>
<ElasticEase Oscillations="0" Springiness="1" />
</DoubleAnimation.EasingFunction>
</DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
这是我的第二个故事板,将球向右移动 40 像素:
<EventTrigger>
<BeginStoryboard>
<Storyboard x:Name="ballstoryright">
<DoubleAnimation Storyboard.TargetName="balltrans" Storyboard.TargetProperty="TranslateX"
Duration="0:0:0.5" By="40" FillBehavior="HoldEnd">
<DoubleAnimation.EasingFunction>
<ElasticEase Oscillations="0" Springiness="1" />
</DoubleAnimation.EasingFunction>
</DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
我在后面的代码中编写了这段代码:
private void imgleft_Tapped(object sender, TappedRoutedEventArgs e)
{
ballstoryleft.Begin();
}
private void imgright_Tapped(object sender, TappedRoutedEventArgs e)
{
ballstoryright.Begin();
}