I try to implement animation of the set of different controls with different height with Canvas and Stackpanel.
So I populate Stackpanel and apply all settings but anyway in the beginning animation is jumping for some time and only after this goes smoothly and when it ends it is again jumping 2-3 times and etc….
Any clue why is it? I use classic double animation and etc…
THANK YOU FOR ANY CLUE!
<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);
}
I have even tried like this
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();
I mean the animation doesn’t start smoothly it is jumping.. but later goes quite well…
When I have animation performance issues, I can usually mitigate them by lowering the
FrameRateand easing the demand on the rendering system. In myApplicationStartup method, I add the following:The WPF default is 60 (which is ridiculous, since even modern video never exceeds 30 FPS). I usually find a good performance balance around 10, but you can adjust this number until your animations look and perform as you want them to.
I hope this helps.