2013-03-21 29 views
0

我正在使用兩個故事板來移動球(圖像)的左右方向,點擊左按鈕的事件時我想向左移動球並且點擊右按鈕的事件時,球應該朝向正確的方向移動。它在錄製左右按鈕時正常工作,但在加載應用程序故事板時會自動開始並且球不移動按鈕就會移動一個步驟。如何限制故事板自動開始?如何限制故事板在Windows 8商店應用程序中自動開始?

這是我的第一個故事板來移動球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(); 
} 

回答

1

你在哪裏放了Storyboards?我看到他們在EventTriggers之內。他們可能是應用程序加載時觸發故事板的人。

你應該只把兩隻StoryboardsResources集合:

<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> 

現在應該沒有理由讓他們自動觸發,而你的代碼,從而引發他們對自來水還是應該工作,就像現在這樣。

+0

先生感謝名單,它的工作原理..! – 2013-03-21 06:04:02

0

您可以從代碼中定義整個故事板後也

試試這個例子:

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(); 
    } 
+0

這也是更好的方法來做到這一點.. – 2013-03-21 06:59:06

相關問題