wpf 字幕动画切换
我用timer计时,在第25秒切换另一个字幕,但是结果动画有点卡住了,显示位置也不正确。过10多少之后才正常
代码如下
//上翻跑马灯
private void playY()
{
this.story = new Storyboard();
this.story2 = new Storyboard();
this.marquee.Background = Brushes.Pink;
this.marquee2.Background = Brushes.Green;
this.grid.Background = Brushes.Yellow;
int intRuntime = 1;
this.textHeight = this.MeasureTextHeight();
this.marquee.Height = this.textHeight;
this.marquee2.Height = this.textHeight;
this.grid.Height = this.textHeight;
marquee2.Content = marquee.Content;
this.rowHeight = this.textHeight;
this.playFrom = this.rowHeight;
this.playTo = 0;
DoubleAnimation animation = new DoubleAnimation();
animation.Duration = TimeSpan.FromSeconds(intRuntime);
animation.From = this.playFrom;
animation.To = this.playTo;
Storyboard.SetTargetName(animation, "lab");
Storyboard.SetTargetProperty(animation, new PropertyPath(TranslateTransform.YProperty));
this.story.Duration = TimeSpan.FromSeconds(intRuntime);
this.story.Children.Add(animation);
this.story.FillBehavior = FillBehavior.Stop;
this.story.Completed += new EventHandler(story_Completed);
this.story.Begin(this, true);
this.playFrom2 = this.playFrom + this.textHeight;
this.playTo2 = this.playFrom2 - this.rowHeight;
DoubleAnimation animation2 = new DoubleAnimation();
animation2.Duration = TimeSpan.FromSeconds(intRuntime);
animation2.From = playFrom2;
animation2.To = playTo2;
Storyboard.SetTargetName(animation2, "lab2");
Storyboard.SetTargetProperty(animation2, new PropertyPath(TranslateTransform.YProperty));
this.story2.Duration = TimeSpan.FromSeconds(intRuntime);
this.story2.Children.Add(animation2);
this.story2.FillBehavior = FillBehavior.Stop;
this.story2.Completed += new EventHandler(story2_Completed);
this.story2.Begin(this, true);
}