Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

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

like image 584
Cameron Peters Avatar asked Mar 31 '11 04:03

Cameron Peters


1 Answers

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>
like image 72
Kishore Kumar Avatar answered Oct 16 '22 09:10

Kishore Kumar