I want to be able to animate the collapse of a <StackPanel>
when I change its visibility to Collapsed. I found this Question for which the accepted answer gets me close. I have created this XAML Code:
<Grid x:Name="grdBRDS">
<Grid.Resources>
<Style TargetType="StackPanel" x:Key="XPND">
<Setter Property="RenderTransform">
<Setter.Value>
<ScaleTransform ScaleX="1"/>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="Tag" Value="Hide">
<Trigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="RenderTransform.ScaleX"
From="1" To="0"
Duration="0:00:1"/>
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
</Trigger>
<Trigger Property="Tag" Value="Show">
<Trigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="RenderTransform.ScaleX"
From="0" To="1"
Duration="0:00:1"/>
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
</Trigger>
</Style.Triggers>
</Style>
</Grid.Resources>
<StackPanel x:Name="pnlTRG" Orientation="Horizontal" Margin="7" Style="{StaticResource XPND}">
I have two buttons with these Click Events:
Private Sub btnCLPS_Click(sender As Object, e As RoutedEventArgs) Handles btnCLPS.Click
pnlTRG.Tag = "Hide"
btnCLPS.Visibility = 2 'This is just to have the buttons replace each other rather than create
btnEXPD.Visibility = 0 'logic for which action to invoke
End Sub
Private Sub btnEXPD_Click(sender As Object, e As RoutedEventArgs) Handles btnEXPD.Click
pnlTRG.Tag = "Show"
btnCLPS.Visibility = 0
btnEXPD.Visibility = 2
End Sub
Everything works fine once through. But after I collapse the <StackPanel>
and then expand it, the collapsing no longer works, though the expansion will (it snaps to scale 0 then grows to scale 1). What am I missing?