WPF Stackpanel可见性动画 [英] WPF stackpanel visibility animation

查看:385
本文介绍了WPF Stackpanel可见性动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有按钮的堆栈面板,单击该按钮可使堆栈面板消失.我想设置从可见到隐藏的过渡形式的动画,但一直无法.

I have a stackpanel with a button which, when clicked, makes the stackpanel disappear. I want to animate the transition form visible to hidden, but haven't been able to.

我环顾了一会儿,撞到了看起来像这样的东西:

I looked around for a while and bumped into something that looks like this:

<StackPanel Margin="80,60,60,80" Background="Gray">
    <StackPanel.Triggers >

        <EventTrigger  > 
            <EventTrigger.Actions>
                <BeginStoryboard>
                    <Storyboard TargetProperty="Visibility">

                        <DoubleAnimation Duration="0:0:5:0" From="Visible" To="Hidden"/>

                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger.Actions>
        </EventTrigger>

    </StackPanel.Triggers>
    <Button Name="buttonTop" Content="TOP" Margin="40,40,40,40" Click="buttonTop_Click" Width="131" />
</StackPanel>

那当然还不是100%.有任何想法吗?

which of course, is not 100% there yet. Any ideas?

推荐答案

您可以使用

<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ItemsHost"
                               Storyboard.TargetProperty="Visibility">
    <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="{x:Static Visibility.Visible}"/>
</ObjectAnimationUsingKeyFrames>

这几乎是情节提要中的设置器,其中KeyTime描述了应设置值的时间. 因此,完整的故事板将如下所示:

This is pretty much a setter in a storyboard, where KeyTime describes the time when the value should be set. So the full storyboard would be like this:

<BeginStoryboard>
    <Storyboard>
        <DoubleAnimation Storyboard.TargetProperty="Opacity"
                         To="0" Duration="0:0:5.0"/>
        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility">
            <DiscreteObjectKeyFrame KeyTime="0:0:5.0" Value="{x:Static Visibility.Hidden}"/>
        </ObjectAnimationUsingKeyFrames>
    </Storyboard>
</BeginStoryboard>

如何在单击按钮时触发情节提要:

edit: How to make the storyboard trigger when button is clicked:

<Button Content="Button" HorizontalAlignment="Left" Margin="337,221,0,0" VerticalAlignment="Top" Width="75">
    <Button.Triggers>
        <EventTrigger RoutedEvent="Button.Click">
            <BeginStoryboard>
                <Storyboard>
                    <DoubleAnimation Storyboard.TargetProperty="Opacity"
                 To="0" Duration="0:0:5.0"/>
                    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility">
                        <DiscreteObjectKeyFrame KeyTime="0:0:5.0" Value="{x:Static Visibility.Hidden}"/>
                    </ObjectAnimationUsingKeyFrames>
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
    </Button.Triggers>
</Button>

这篇关于WPF Stackpanel可见性动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆