wpf 字幕动画切换

zhantianyou 2012-06-28 05:37:51
我用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);
}
...全文
145 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
SleepingBug 2012-07-10
  • 打赏
  • 举报
回复
Hasan, 请加我QQ 309301760,有事找你。
zhantianyou 2012-06-28
  • 打赏
  • 举报
回复
void timer_Tick(object sender, EventArgs e)
{
Stop();
setContent("testestekasdjfksajfkasj");
run();
DispatcherTimer timer = sender as DispatcherTimer;
timer.IsEnabled = false;
}

public void Stop()
{
if (this.story != null)
{
this.story.Stop(this);
// this.story = null;
}

if (this.story2 != null)
{
this.story2.Stop(this);
// this.story2 = null;
}
}
zhantianyou 2012-06-28
  • 打赏
  • 举报
回复
private void story_Completed(object sender, EventArgs e)
{
double span = Math.Abs(this.textHeight - Math.Abs(this.playTo));

if (span >= this.rowHeight)
{
this.playFrom = this.playTo;
this.playTo -= this.rowHeight;
}
else
{
this.playFrom = this.rowHeight;
this.playTo = this.playFrom - this.rowHeight;
}

DoubleAnimation animation = (DoubleAnimation)this.story.Children[0];
animation.From = this.playFrom;
animation.To = this.playTo;
this.story.BeginTime = TimeSpan.FromSeconds(5);
this.story.Begin(this);
}

private void story2_Completed(object sender, EventArgs e)
{
double span = this.playTo2 + this.textHeight;
if (span >= this.rowHeight)
{
this.playFrom2 = this.playTo2;
this.playTo2 -= this.rowHeight;
}
else
{
this.playFrom2 = this.playFrom + this.textHeight;
this.playTo2 = this.playFrom2 - this.rowHeight;
}
DoubleAnimation animation = (DoubleAnimation)this.story2.Children[0];
animation.From = this.playFrom2;
animation.To = this.playTo2;
this.story2.BeginTime = TimeSpan.FromSeconds(5);
this.story2.Begin(this);
}

110,568

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧