2012-01-11 8 views
0

トップ通知アニメーションを作成していますが、アニメーションが終了するまでアニメーションを同期させる方法がわかりません。ここに私が持っているコードです:Windowsの電話アニメーションのコードブロックが終了するまで他のスレッドを無効にする方法

public Storyboard prepareShowStory(int count, NotificationControl notifyControl) 
     { 
      notifyControl.textBlock1.Text = "Got" + count.ToString() + "Message"; 

      notifyControl.RenderTransform = new CompositeTransform(); 
      Storyboard story = new Storyboard(); 
      //From here until the annimation finish and remove LayoutRoot.Resources.Clear(); 
      LayoutRoot.Resources.Add("unique_id", story); 

      story.Completed += (object sender, EventArgs e) => 
      { 
       story.Stop(); 
       story.Children.Clear(); 
       App.ViewModel.myAction -= CompletedRefresh; 
       LayoutRoot.Resources.Clear(); 
       //To here. 
      }; 
      story.Begin(); 

      DoubleAnimation animation; 
      animation = new DoubleAnimation(); 
      animation.AutoReverse = true; 
      animation.From = -64; 
      animation.To = 60; 
      animation.Duration = new Duration(TimeSpan.FromMilliseconds(1600)); 
      animation.EasingFunction = _EasingFunction; 
      Storyboard.SetTargetName(animation, notifyControl.Name); 
      Storyboard.SetTargetProperty(animation, new PropertyPath("(UIElement.RenderTransform).(CompositeTransform.TranslateY)")); 
      story.Children.Add(animation); 

      return story; 
     } 
+0

「story.begin」の終了後に「story」を返すことを意味しますか? – keyboardP

+0

LayoutRoot.Resources.Clear()をクリアしたい。アニメーションが終了したとき、そうでなければ、別のスレッドがLayoutRoot.Resources.Add( "unique_id"、story)に来たとき。 agianが、仕上げが完了していない場合、システムはエラー「2回追加」を報告します。 –

答えて

0

あなたはそれに追加する前にResourceDictionaryをチェックすることができます。

if(!LayoutRoot.Resources.Contains("unique_id")) 
    LayoutRoot.Resources.Add("unique_id", story); 
+0

"同じキーを持つアイテムが既に追加されています"というエラーが表示されます。限られた時間で関数が2回呼び出された場合。プライベート無効CompletedRefresh(int型の数) { this.Dispatcher.BeginInvoke(()=> { するvar物語= prepareShowStory(、this.notificationControl1カウント); story.Begin(); }); } –

+0

この行にはどのエラーがスローされますか?追加する前にそのキーがすでに存在する場合はチェックできませんか? – keyboardP

+0

この行は、LayoutRoot.Resources.Add( "unique_id"、story)というエラーを報告します。アニメーションが終了していないので、私は関数agianを呼び出すので、エラーを報告しますが、アニメーションが終了するまで関数をロックする方法はわかりません。どうもありがとう!! –

関連する問題