开发者

How to show a grid for few seconds in WPF?

开发者 https://www.devze.com 2023-01-14 00:51 出处:网络
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 s

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

精彩评论

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