仿vista窗口弹出、关闭时的动画效果代码
程序员文章站
2022-03-01 13:05:29
...
在vista操作系统中,对于窗口的一大亮点就是在窗口加载和关闭的时候总是从小到大弹出,关闭的时候则是从大到小逐渐消失。在WPF中可以很轻松的实现这一效果,其代码如下(在不同的项目中需要修改一些参数):
该代码定义到资源文件中比较好。
<Window.Resources>
<!-- Show Chat Window Animation -->
<Storyboard x:Key="showChatWindow">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Window" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)">
<SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
<SplineDoubleKeyFrame KeyTime="00:00:001" Value="1"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="ChatControl" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)">
<SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
<SplineDoubleKeyFrame KeyTime="00:00:001" Value="1"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<!-- Close Chat Window Animation -->
<Storyboard x:Key="hideChatWindow">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Window" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)">
<SplineDoubleKeyFrame KeyTime="00:00:00" Value="1"/>
<SplineDoubleKeyFrame KeyTime="00:00:001" Value="0"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="ChatControl" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)">
<SplineDoubleKeyFrame KeyTime="00:00:00" Value="1"/>
<SplineDoubleKeyFrame KeyTime="00:00:001" Value="0"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</Window.Resources>
该代码定义到资源文件中比较好。
上一篇: 并行计算随笔(二)