我正在尝试使用WPF动画,但卡住了。这是我需要做的:
鼠标悬停:
淡入(在2秒内从0%到100%不透明度)
鼠标移开:
暂停2秒
淡出(在2秒内从100%到0%不透明度)
我已经掌握了淡入和淡出效果,但无法想象如何实现暂停,甚至不确定是否可能。
<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
属性。