如何在WPF中显示网格几秒钟?

时间:2010-08-31 09:13:52

标签: wpf

我有一个可以通过代码控制Visibility的网格。我希望网格在变为可见之后被隐藏,比如说在5秒之后。在WPF中有什么简单的方法吗?

2 个答案:

答案 0 :(得分:1)

你可以在Opacity属性上使用DoubleAnimationUsingKeyFrames的故事板(这只会隐藏网格,而不是折叠它)。

答案 1 :(得分:0)

添加以下代码:

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