显示隐藏的动画

一:xaml版

<TextBlock Height="23" HorizontalAlignment="Left" Cursor="Hand" Margin="10,10,0,0" Name="tbClick" Text="Click To Show" VerticalAlignment="Top" />
        <ListView Name="lvRoot" Width="200" Height="0">
            <ListView.View>
                <GridView>
                    <GridViewColumn DisplayMemberBinding="{Binding ShowColor}" Header="Color" Width="200" />
                </GridView>
            </ListView.View>
        </ListView>

二:后台绑定

DoubleAnimation animation = null;
            if (!flag)
            {
                animation = new DoubleAnimation();
                animation.From = 0;
                animation.To = 200;
                animation.Duration = new Duration(TimeSpan.FromSeconds(1));
                Storyboard.SetTargetName(animation, lvRoot.Name);
                Storyboard.SetTargetProperty(animation, new PropertyPath(HeightProperty));
                flag = true;
            }
            else
            {
                animation = new DoubleAnimation();
                animation.From = 200;
                animation.To = 0;
                animation.Duration = new Duration(TimeSpan.FromSeconds(1));
                Storyboard.SetTargetName(animation, lvRoot.Name);
                Storyboard.SetTargetProperty(animation, new PropertyPath(ListView.HeightProperty));
                flag = false;
            }
            Storyboard board = new Storyboard();
            board.Children.Add(animation);
            board.Begin(this);
原文地址:https://www.cnblogs.com/kelei12399/p/2594676.html