0

と を使用して、高さが異なるさまざまなコントロールのセットのアニメーションを実装しようとしていCanvasますStackpanel

したがってStackpanel、すべての設定を入力して適用しますが、最初はアニメーションがしばらくジャンプし、その後スムーズに進み、終了すると再び2〜3回ジャンプします....

それはなぜですか?古典的なダブルアニメーションなどを使用しています...

手がかりをありがとう!

<Canvas  ClipToBounds="True" Name="canMain" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" >
   <StackPanel  Name="tbmarquee" HorizontalAlignment="Stretch"  ></StackPanel>
</Canvas> 

private void BottomToTopMarquee()
{
     tbmarquee.Orientation = Orientation.Vertical;  
     DoubleAnimation doubleAnimation = new DoubleAnimation();
     doubleAnimation.From = -tbmarquee.ActualHeight;
     doubleAnimation.To = canMain.ActualHeight;
     doubleAnimation.RepeatBehavior = RepeatBehavior.Forever;
     doubleAnimation.Duration = new Duration(TimeSpan.FromSeconds(_marqueeTimeInSeconds));
     tbmarquee.BeginAnimation(Canvas.BottomProperty, doubleAnimation);
 }

私もこのように試しました

   Thread thread = new Thread(new ThreadStart(
            delegate()
            {
                DispatcherOperation dispatcherOp =
                  this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(
                    delegate()
                    {

                        DoubleAnimation doubleAnimation = new DoubleAnimation();
                        doubleAnimation.From = -tbmarquee.ActualHeight;
                        doubleAnimation.To = canMain.ActualHeight;
                        doubleAnimation.RepeatBehavior = RepeatBehavior.Forever;
                        doubleAnimation.Duration = new Duration(TimeSpan.FromSeconds(_marqueeTimeInSeconds));
                        tbmarquee.BeginAnimation(Canvas.BottomProperty, doubleAnimation);
                    }));
                dispatcherOp.Completed += new EventHandler(DispatcherOpCompleted);
            }));
            thread.Start();

つまり、アニメーションがスムーズに開始されず、ジャンプしています..しかし、後で非常にうまくいきます...

4

1 に答える 1

2

FrameRateアニメーションのパフォーマンスに問題がある場合は、通常、レンダリング システムの要求を下げて緩和することで問題を軽減できます。私のApplicationStartup メソッドでは、次を追加します。

MediaTimeline.DesiredFrameRateProperty.OverrideMetadata(typeof(System.Windows.Media.Animation.Timeline), new FrameworkPropertyMetadata(10));

WPF のデフォルトは 60 です (最新のビデオでさえ 30 FPS を超えることはないため、これはばかげています)。通常は 10 前後のパフォーマンス バランスが良いと思いますが、アニメーションの外観とパフォーマンスが希望どおりになるまで、この数を調整できます。

これが役立つことを願っています。

于 2012-11-26T19:33:37.477 に答える