How to show a grid for few seconds in WPF?
I have a grid of which Visibil开发者_开发问答ity 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?
You can use a storyboard with DoubleAnimationUsingKeyFrames on the Opacity property (this will only hide the grid though, not collapse it).
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>
精彩评论