tags:

views:

33

answers:

2

I have a grid of which Visibility I control from code. I want the grid to be Hidden after it becomes Visible, say after 5 sec.Are there any easy way of doing this in WPF?

+1  A: 

You can use a storyboard with DoubleAnimationUsingKeyFrames on the Opacity property (this will only hide the grid though, not collapse it).

CommanderZ
A: 

Add the following code:

<Window.Resources>
    <Storyboard x:Key="HideGridSB">
        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="grid" Storyboard.TargetProperty="(UIElement.Opacity)">
             <SplineDoubleKeyFrame KeyTime="00:00:05.000000" Value="0"/>
        </DoubleAnimationUsingKeyFrames>
    </Storyboard>
 </Window.Resources>

<Window.Triggers>
  <EventTrigger RoutedEvent="FrameworkElement.Loaded">
       <BeginStoryboard Storyboard="{StaticResource HideGridSB}"/>
  </EventTrigger>
</Window.Triggers>
Homam