I have a stack panel that has visibility bound to a Toggle Button Checked Property and it is working fine. However the only additional effect I want for the stack panel is to slide up and down to give a better user experience.
Here is my Xaml
<Window.Resources>
<ResourceDictionary>
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
</ResourceDictionary>
</Window.Resources>
<ToggleButton x:Name="Products" Tag="" Content="Products" Template="{StaticResource MenuButton}" Style="{StaticResource MenuItem}"/>
<StackPanel Background="{StaticResource MenuItemBrush}" Visibility="{Binding ElementName=Products, Path=IsChecked, Converter={StaticResource BooleanToVisibilityConverter}}">
<ToggleButton Padding="30,0,0,0" Content="Menu Item" Template="{StaticResource MenuButton}" Style="{StaticResource SubMenuItem}"/>
</StackPanel>
Can you guys please suggest the right way of achieving this? Ideally I would like to add a style that can be reused on other panels as well.
Thanks
Update:
I was able to apply the style for animating the visibility from collapsed to visible and animation works fine, but I still cannot figure out how to animate stack panel when it is collapsing. It just jumps into collapsed state. Here is the style:
<Style x:Key="MyStyle" TargetType="{x:Type StackPanel}">
<Setter Property="RenderTransform">
<Setter.Value>
<ScaleTransform ScaleY="1"/>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="Visibility" Value="Visible">
<Trigger.EnterActions>
<BeginStoryboard>
<Storyboard >
<DoubleAnimation Storyboard.TargetProperty="RenderTransform.ScaleY" From="0" Duration="0:00:.300"/>
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
</Trigger>
<Trigger Property="Visibility" Value="Collapsed">
<Trigger.EnterActions>
<BeginStoryboard>
<Storyboard >
<DoubleAnimation Storyboard.TargetProperty="RenderTransform.ScaleY" From="1" Duration="0:00:.300"/>
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
</Trigger>
</Style.Triggers>
</Style>