views:

1427

answers:

5

In WPF 3.5 (with SP1), I have simply StackPanel that I would like to animate when I change the property Visibility. I have no idea of the height of this StackPanel since its content determines its height. So when I change the property of my StackPanel to Visible (progressPanel.Visibility = Visibility.Visible;) I would like to see an animation (probably an DoubleAnimationUsingKeyFrames from 0 to X).

Moreover, I have multiple StackPanel that I would like to see with this behavior (so in the best case, I need something generic). Does anybody have an idea on how to do that?

Thanks!

+1  A: 

If you need an expanding kind of effect with an animation which grows vertically. Do a double animation on the ScaleTransform.ScaleY property of the panel from 0 to 1 if it is a vertical oriented panel.

Jobi Joy
Why a negative for me :). When you can't determine the actual height of the stackPanel it is better to animate the ScaleTransform.ScaleX from 0 to 1 which will do the trick, try it out and then vote down.
Jobi Joy
Just edit your post and I'll vote up.
Martin
+1  A: 

You can create and reuse custom StackPanel style that triggers animation when Visibility changes:

<Style x:Key="MyStyle" TargetType="{x:Type StackPanel}">
    <Style.Triggers>
        <Trigger Property="Visibility" Value="Visible">
            <Trigger.EnterActions>
                <BeginStoryboard>
                    <Storyboard >
                        <DoubleAnimation .../>
                    </Storyboard>
                </BeginStoryboard>
            </Trigger.EnterActions>
        </Trigger>
    </Style.Triggers>
</Style>
aku
You answered very well part of my question. The second part is how the Height of the StackPanel. Considering that I don't know the height, how do I use the DoubleAnimation?<DoubleAnimation Storyboard.TargetProperty="(FrameworkElement.Height)" From="0" To="--???--" Duration="00:00:00.5" />
Martin
It's not clear what kind of effect you want to achieve. Please update you're question and provided detailed info on desired StackPanel's behavior. Manually changing StackPanel.Height property doesn't look like a good idea to me
aku
A: 

Did you ever solidify a solution; would you mind posting the XAML if you did.

Thanks! Aj

Aaj
A: 

The Reveal control from Kevin's Bag-o-Tricks ( http://j832.com/bagotricks/ ) does exactly that.

Nir
A: 

Adding rendertransform on stackpanel does not seem to do the trick for me as my stackpanel is withing a GRID that has some rectangles as well, and the stackpanel width is dynamically set by the contents I put in it. I tried: Visible Collapsed

But this does not really "animate" It just waits 4 sec and immediately closes "collapses" the stackpanel... I want it to close slllooooowwwwly (like in 4 secs)...

Any HELP posting would help us all! thanks, Anastasia