C# 如何限制情节提要在Windows 8应用商店应用程序中自动开始?

C# 如何限制情节提要在Windows 8应用商店应用程序中自动开始?,c#,windows-8,storyboard,winrt-xaml,C#,Windows 8,Storyboard,Winrt Xaml,我使用两个故事板向左和向右移动球(图像),点击左键的事件我想向左移动球,点击右键的事件,球应该向右移动。它在点击左键和右键时工作正常,但在加载应用程序时,故事板会自动开始,球会移动一步而不点击按钮。如何限制情节提要自动开始 这是我第一个将球向左移动40像素的故事板: <EventTrigger> <BeginStoryboard> <Storyboard x:Name="ballstoryleft"> <DoubleAnimation Storyboa

我使用两个故事板向左和向右移动球(图像),点击左键的事件我想向左移动球,点击右键的事件,球应该向右移动。它在点击左键和右键时工作正常,但在加载应用程序时,故事板会自动开始,球会移动一步而不点击按钮。如何限制情节提要自动开始

这是我第一个将球向左移动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>              
<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>

你把你的故事板放在哪里了?我看到它们在
EventTriggers
中。它们可能是在应用程序加载时触发故事板的

您应该将两个
故事板
放在
资源
集合中:

<Page.Resources>
    <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>
    <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>
</Page.Resources>


现在应该没有理由让它们自动触发,而您的代码在点击时触发它们,应该仍然可以像现在一样工作。

您也可以从代码隐藏中定义整个故事板

试试这个例子:

void OnButtonClick(object sender, RoutedEventArgs args) 
{ 
  DoubleAnimation anima = new DoubleAnimation
   { 
     EnableDependentAnimation = true,
     To = 96, 
     Duration = new Duration(new TimeSpan(0, 0, 1)), 
     AutoReverse = true, 
     RepeatBehavior = new RepeatBehavior(3) };
     Storyboard.SetTarget(anima, sender as Button);
     Storyboard.SetTargetProperty(anima, "FontSize");
     Storyboard storyboard = new Storyboard();
     storyboard.Children.Add(anima); 
     storyboard.Begin();
  }
void OnButtonClick(object sender, RoutedEventArgs args) 
{ 
  DoubleAnimation anima = new DoubleAnimation
   { 
     EnableDependentAnimation = true,
     To = 96, 
     Duration = new Duration(new TimeSpan(0, 0, 1)), 
     AutoReverse = true, 
     RepeatBehavior = new RepeatBehavior(3) };
     Storyboard.SetTarget(anima, sender as Button);
     Storyboard.SetTargetProperty(anima, "FontSize");
     Storyboard storyboard = new Storyboard();
     storyboard.Children.Add(anima); 
     storyboard.Begin();
  }