2012-04-06 19 views
1

アニメーションには比較的新しいので、少しの方向性を探しています。私はList<Label>を15個のラベルが入っているとしましょう。私はDoubleAnimationを持っています。これは500 msでm 0から1の不透明度をアニメーション化します。私はループしたいと思います。これらのラベルは1000msごとにアニメーションを開始します。私は* 15を1000ミリ秒とSBに私のラベルを追加し、それを開始するためにStoryboard.Durationを設定することができます知っているが、アニメーションが早く彼らが追加されているとしてプレー1000ミリ秒で始まり、LABEL2は0msでそうLABEL1開始など特定の時間間隔でアニメーションを追加する

SB。特定の時間間隔でSBにアニメーションを追加する方法はありますか?

EDIT: 私はここでもう をList<Label>を使用していないよ、私はあなたが単に各アニメーションのBeginTimeを設定することができ

class MessageWriter 
{ 
    Storyboard _sb = new Storyboard(); 
    public MessageWriter() 
    { 

    } 

    public void ProcessMessage(string _Message, WrapPanel _Panel) 
    { 
     string[] _Words = _Message.Split(new char[1]{Convert.ToChar(" ")}); 
     int _Counter = 1; 
     _sb = new Storyboard(); 
     foreach (string _Word in _Words) 
     { 
      _Panel.Children.Add(ProcessWord(_Word)); 
      if (_Counter < _Words.Length) 
      { 
       _Panel.Children.Add(ProcessWord(" ")); 
      } 
      _Counter++; 
     } 
     _sb.Begin(); 
    } 

    private StackPanel ProcessWord(string _Word) 
    { 
     Debug.Print(_Word); 
     StackPanel _Panel = new StackPanel(); 
     _Panel.Orientation = Orientation.Horizontal; 
     _Panel.Margin = new System.Windows.Thickness(0, 0, 0, 0); 

     foreach (char _c in _Word.ToList()) 
     { 
      Label _Label = new Label(); 
      _Label.Opacity = 0; 
      _Label.Margin = new System.Windows.Thickness(0, 0, 0, 0); 
      _Label.Padding = new System.Windows.Thickness(0, 0, 0, 0); 
      _Label.Content = _c.ToString(); 
      _Panel.Children.Add(_Label); 
      AnimateLabel(_Label); 
     } 
     return _Panel; 
    } 

    private void AnimateLabel(Label _Label) 
    { 
     DoubleAnimation _da = new DoubleAnimation(); 
     _da.From = 0; 
     _da.To = 1; 

     int _MillSec = 500; 
     _da.Duration = new System.Windows.Duration(new TimeSpan(0, 0, 0, 0, _MillSec)); 

     Storyboard.SetTargetProperty(_da, new PropertyPath(FrameworkElement.OpacityProperty)); 
     Storyboard.SetTarget(_da, _Label); 
     _sb.Children.Add(_da); 
    } 
} 

答えて

3

を書いたコードです。

ストーリーボードは絶対に必要ありません。ラベルにアニメーションを適用するだけです:

DoubleAnimation opacityAnimation = new DoubleAnimation 
{ 
    To = 1d, 
    Duration = TimeSpan.FromSeconds(0.5), 
    BeginTime = TimeSpan.FromSeconds((double)labelIndex) 
}; 
labelIndex++; 
label.BeginAnimation(UIElement.OpacityProperty, opacityAnimation); 

なぜ、その変な名前がすべての変数名に下線を引いていますか?広く受け入れられているのは.Net naming conventionsです。

+0

このインスタンスではうまくいきました。ありがとうございました。誰かがストーリーボードを使ってこれを行う方法を詳しく説明したいと思うなら、それは認められるでしょう。将来的にはいくつかの作業を行う必要がありますので、タイムラインを最初に作成してからやり直す必要があります。 – Jmyster

+0

これは、ストーリーボードに追加するアニメーションでも機能します。それはもっと簡単です。 – Clemens

+0

そしてアンダースコアは私が拾った悪い習慣です。私はかなり肛門性交し、すべての私の変数のために同じプレフィックスを持つ必要があります。私はまだ問題がなかったので、私は変わったことはありません。 – Jmyster

関連する問題