Martin Cook

Martin Cook

  • NA
  • 46
  • 0

Animating transition with wrap panel content

Feb 10 2010 5:58 AM
Hi All,

This is my first post so go easy on me ;)

I've developed a custom control that houses one or more panes.  Switching between the child panes is presented using a slide animation to depict the transition.  When the panes contain quite a few controls the transition animation becomes noticably stuttery.  Here's the code that performs the animation: -

 AccordianPane paneToAnimate = _panes.FirstOrDefault(p => p.IsExpanded);
Storyboard expandStoryboard = new Storyboard();
DoubleAnimation da = new DoubleAnimation();
da.To = ActualWidth - ((_panes.Count - 1) * CollapsedPaneWidth) > 0 ? ActualWidth - ((_panes.Count - 1) * CollapsedPaneWidth) : 1;
da.Duration = TimeSpan.FromSeconds(instant ? 0 : SlideSpeed);
Storyboard.SetTarget(da, paneToAnimate);
Storyboard.SetTargetProperty(da, new PropertyPath("(FrameworkElement.Width)"));
expandStoryboard.Children.Add(da);
expandStoryboard.Begin();

Any help or advice would be greatly appreciated.

Thank you.