Reputation: 40573
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!
Upvotes: 3
Views: 6662
Reputation: 50038
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.
Upvotes: 2
Reputation: 123966
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>
Upvotes: 4