WPF仿QQ启动时渐变动画

感谢基友Xblack提供方法。

主要用到的就是OpacityMask,通过OpacityMask来设置不透明模板,然后使用Triggers控制动画。源码如下

 


<Window.OpacityMask>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="0"/>
<GradientStop x:Name="StopX" Color="Black" Offset="0"/>
<GradientStop x:Name="StopY" Offset="1"/>
<GradientStop Offset="1"/>
</LinearGradientBrush>
</Window.OpacityMask>
<Window.Triggers>
<EventTrigger SourceName="Window" RoutedEvent="Loaded">
<BeginStoryboard>
<Storyboard TargetName="StopX" TargetProperty="Offset">
<DoubleAnimation From="0" To="1" BeginTime="0:0:0.05" Duration="0:0:0.25"/>
</Storyboard>
</BeginStoryboard>
<BeginStoryboard>
<Storyboard TargetName="StopY" TargetProperty="Offset">
<DoubleAnimation From="0" To="1" Duration="0:0:0.2"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Window.Triggers>

发表评论

邮箱地址不会被公开。 必填项已用*标注