代码之家  ›  专栏  ›  技术社区  ›  JustinT

WPF动画暂停/继续

  •  3
  • JustinT  · 技术社区  · 16 年前

    我正在尝试WPF动画,我有点卡住了。以下是我需要做的:

    淡入(2秒内不透明度为0%到100%)

    暂停2秒钟

    淡出(2秒内不透明度为100%到0%)

    我有淡入淡出效果,但我不知道如何实现暂停,甚至不知道是否可能。

    1 回复  |  直到 16 年前
        1
  •  5
  •   Drew Noakes    16 年前

    Kaxaml 要尝试:

    <Page
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
      <Grid Background="Red">  
        <Grid.Triggers>
          <EventTrigger RoutedEvent="Grid.Loaded">
            <EventTrigger.Actions>
              <BeginStoryboard>
                <Storyboard RepeatBehavior="Forever">
                  <DoubleAnimation Storyboard.TargetProperty="Opacity"
                                   From="1" To="0" 
                                   Duration="0:00:02"
                                   BeginTime="0:00:02" />
                </Storyboard>
              </BeginStoryboard>
            </EventTrigger.Actions>
          </EventTrigger>
        </Grid.Triggers>
      </Grid>
    </Page>
    

    诀窍是使用 BeginTime DoubleAnimation