我用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);
        }

解决方案 »

  1.   

     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);
            }
      

  2.   

     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;
                }
            }
      

  3.   

    Hasan, 请加我QQ 309301760,有事找你。