我对动画比较陌生,所以我正在寻找一些方向。假设我List<Label>
加载了一个带有 15 个标签的标签。我有DoubleAnimation
在 500 毫秒内将不透明度从 0 设置为 1 的动画。我想循环,这些标签每 1000 毫秒开始一次动画。所以label1从0ms开始,label2从1000ms开始等等。
我知道我可以将 a 设置Storyboard.Duration
为 1000ms*15 并将我的标签添加到 SB 并开始它,但是动画播放的速度与添加到 SB 的速度一样快。有没有办法以特定的时间间隔将动画添加到 SB?
编辑:
我不再使用List<Label>
了这是我写的代码
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);
}
}