WPF中的视觉效果、动画、媒体与数据处理
1. WPF动画系统
WPF的动画系统功能丰富,除了LinearDoubleKeyFrame外,还有其他类型的关键帧。动画定义可非常复杂,借助时间线组合,能嵌套和排列动画以实现所需效果。例如下面的代码展示了一个使用关键帧的双精度动画:
<DoubleAnimationUsingKeyFrames Storyboard.TargetName='_target' Storyboard.TargetProperty='Height'> <LinearDoubleKeyFrame KeyTime='0:0:0' Value='5' /> <LinearDoubleKeyFrame KeyTime='0:0:2' Value='5' /> <LinearDoubleKeyFrame KeyTime='0:0:4' Value='25' /> <LinearDoubleKeyFrame KeyTime='0:0:12' Value='45' /> </DoubleAnimationUsingKeyFrames>1.1 动画与控件模板集成
动画可嵌入控件中,以创建交互性强的控件。比如,当鼠标悬停在按钮上时,改变按钮边框的厚度和颜色。可通过定义ControlTemplate中的Storyboard来实现,示例代码如下: