wpf 使用 XAML 在 Storyboard 完成时将元素的可见性设置为折叠

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5495446/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 22:43:39  来源:igfitidea点击:

Setting the Visibility of an Element to Collapsed when Storyboard completes using XAML

wpfxamlstoryboard

提问by Cameron Peters

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.

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

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.

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

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

我知道我可以连接事件,但我想在 XAML 中完成这一切。是否可以?

回答by Kishore Kumar

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>