开发者

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

开发者 https://www.devze.com 2023-02-21 03:27 出处:网络
I have a storyboard animation that fades a con开发者_如何学编程trol out of view using the Opacity property.When it completes, I want to set the Visibility of the control to Collapsed.

I have a storyboard animation that fades a con开发者_如何学编程trol 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.

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>
0

精彩评论

暂无评论...
验证码 换一张
取 消