views:

174

answers:

2

In my case, I would like the expand/collapse to happen from left to right and right to left respectively.

The animation should happen when the visibility changes.

Thank you.

A: 

You could create two animation storyboards (One for expanding and one for Collapsing) that animates the Width of the stackpanel, then on StackPanel_VisibilityChanged run the appropriate animation.

Rachel
Do you have an example that animates the current width of the StackPanel? All the examples I see are based on fixed widths.
Brandon
I remember doing something like this a while back although I ended up getting rid of it and animating my window differently so I don't have the code on me (switched to a ScaleAnimation which went from 0 to 100%). I think I had the storyboard's DoubleAnimation "From" bound to StackPanel.RenderWidth and "To" set to 0. Animation existed in the Resources, not in a style, and it was ran by calling Storyboard animation = (Storyboard)this.FindResource("StoryboardName"); animation.Begin(); from the code behind.
Rachel
If that doesn't work try animating RenderTransform.(ScaleTransform.ScaleX). That's what I'm currently using. I think if you don't set a CenterPoint it'll animate in place so the effect will be the same as expanding.
Rachel
A: 

I recommend animating on the Width property rather than ScaleX. Otherwise the entire control (StackPanel) will look crunched/stretched as its animating.

AlvinfromDiaspar