使用 XAML 在 Storyboard 完成时将元素的可见性设置为折叠 [英] Setting the Visibility of an Element to Collapsed when Storyboard completes using XAML

查看:25
本文介绍了使用 XAML 在 Storyboard 完成时将元素的可见性设置为折叠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个故事板动画,它使用 Opacity 属性将控件淡出视图.完成后,我想将控件的可见性设置为折叠.

I have a storyboard animation that fades a control out of view using the Opacity property. When it completes, I want to set the Visibility of the control to Collapsed.

我也希望能够反过来做...将可见性设置为可见,然后使用故事板将控件淡入视图中.

I'd like to be able to do the reverse as well... Set the Visibility to Visible and then use a storyboard to fade the control into view.

我知道我可以连接事件,但我想在 XAML 中完成这一切.可能吗?

I know I can hook up events, but I would like to do this all in XAML. Is it possible?

推荐答案

你也可以在动画中这样做

you can do this in the animation as well

<Window.Resources>
    <Storyboard x:Key="OnLoaded1">
        <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="button" Storyboard.TargetProperty="(UIElement.Visibility)">
            <DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{x:Static Visibility.Visible}"/>
            <DiscreteObjectKeyFrame KeyTime="00:00:00.8000000" Value="{x:Static Visibility.Collapsed}"/>
            <DiscreteObjectKeyFrame KeyTime="00:00:01.4000000" Value="{x:Static Visibility.Visible}"/>
        </ObjectAnimationUsingKeyFrames>
    </Storyboard>
</Window.Resources>
<Window.Triggers>
    <EventTrigger RoutedEvent="FrameworkElement.Loaded">
        <BeginStoryboard Storyboard="{StaticResource OnLoaded1}"/>
    </EventTrigger>
</Window.Triggers>

这篇关于使用 XAML 在 Storyboard 完成时将元素的可见性设置为折叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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