WPF 侧边栏隐藏显示动画
<Grid> <Grid.RowDefinitions> <RowDefinition Height="auto" /> <RowDefinition /> </Grid.RowDefinitions> <ToggleButton Grid.Row="0" Width="40" Height="22" Margin="10,10,0,10" HorizontalAlignment="Left"> <ToggleButton.Triggers> <EventTrigger RoutedEvent="ToggleButton.Checked"> <BeginStoryboard> <Storyboard Storyboard.TargetName="bule" Storyboard.TargetProperty="Width"> <DoubleAnimation BeginTime="0:0:0" From="0" To="100" Duration="0:0:0.5" /> </Storyboard> </BeginStoryboard> </EventTrigger> <EventTrigger RoutedEvent="ToggleButton.Unchecked"> <BeginStoryboard> <Storyboard Storyboard.TargetName="bule" Storyboard.TargetProperty="Width"> <DoubleAnimation BeginTime="0:0:0" From="100" To="0" Duration="0:0:0.5" /> </Storyboard> </BeginStoryboard> </EventTrigger> </ToggleButton.Triggers> </ToggleButton> <Grid Grid.Row="1"> <Grid.ColumnDefinitions> <ColumnDefinition Width="auto" /> <ColumnDefinition /> </Grid.ColumnDefinitions> <StackPanel x:Name="bule" Grid.Column="0" Height="{Binding ElementName=stackPanel, Path=ActualHeight}" Background="Blue" /> <StackPanel Grid.Column="1" Height="{Binding ActualHeight, ElementName=stackPanel}" Background="Red" /> </Grid> </Grid>