WPF动画暂停/继续

3

我正在尝试使用WPF动画,但卡住了。这是我需要做的:

鼠标悬停:

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

鼠标移开:

暂停2秒

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

我已经掌握了淡入和淡出效果,但无法想象如何实现暂停,甚至不确定是否可能。

1个回答

5
这里是一段XAML代码,展示了如何实现您想要的功能(您可以将整个代码粘贴到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>

关键是正确使用DoubleAnimation类的BeginTime属性。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接