一、DiscreteDoubleKeyFrame
离散型关键帧动画,重点,我们理解一下“离散”的意思,其实你查一下《新华字典》,“离”和“散”的意思相近。我们可以这样解释:每个关键帧之间是直接过渡,其间不经过动画插补。似乎这样理解有点苦涩难懂,所以,我们还是从实例入手。
请参考以下XAML代码写一个示例:
<Grid Loaded="OnGridLoaded">
<Rectangle Width="100" Height="100" Fill="Green" VerticalAlignment="Top">
<Rectangle.RenderTransform>
<TranslateTransform x:Name="trm"/>
</Rectangle.RenderTransform>
</Rectangle>
<Grid.Resources>
<Storyboard x:Name="std">
<DoubleAnimationUsingKeyFrames Duration="0:0:5" RepeatBehavior="15"
Storyboard.TargetName="trm"
Storyboard.TargetProperty="Y">
<DiscreteDoubleKeyFrame KeyTime="0:0:2" Value="150"/>
<DiscreteDoubleKeyFrame KeyTime="0:0:3" Value="280"/>
<DiscreteDoubleKeyFrame KeyTime="0:0:5" Value="380"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</Grid.Resources>
</Grid>
在后台的C#代码中,千万不要记了启动动画,等下运行后发现动不了就麻烦了。
private void OnGridLoaded(object sender, RoutedEventArgs e)
{
this.std.Begin();
}
然后你可以运行了,注意认真观察动画的演变过程。
不知道你观察到了什么?你是否发现,矩形向下运动的过程是直接跳跃式的,每个关键之间没有创建过渡效果,而且直接跳到对应值。
二、DiscreteColorKeyFrame
这也是一个离散型关键帧动画,从名字上我们知道,它是针对颜色进行动画处理的。还是看例子吧。
请参考下面XAML代码写一个测试程序:
<Grid Loaded="OnGridLoaded">
<Ellipse Width="250" Height="250">
<Ellipse.Fill>
<SolidColorBrush x:Name="brush" Color="Blue"/>
</Ellipse.Fill>
</Ellipse>
<Grid.Resources>
<Storyboard x:Name="std">
<ColorAnimationUsingKeyFrames Duration="0:0:8"
RepeatBehavior="20"
Storyboard.TargetName="brush"
Storyboard.TargetProperty="Color">
<DiscreteColorKeyFrame KeyTime="0:0:2" Value="Yellow"/>
<DiscreteColorKeyFrame KeyTime="0:0:5" Value="Gray"/>
<DiscreteColorKeyFrame KeyTime="0:0:7" Value="Red"/>
</ColorAnimationUsingKeyFrames>
</Storyboard>
</Grid.Resources>
</Grid>
后台代码就不帖了,都懂得写什么了。
然后运行一下,查看效果。
从效果中可以看到,颜色的改变是没有平滑的过渡效果的,而是当时间线的播放时间到了关键帧所在的位置时,颜色是直接改变的。
三、LinearColorKeyFrame
线性颜色的关键帧与离散型动画相反,每个关键帧之间都创建平滑的过渡效果,让人看起来有连续感。
请参考以下XAML代码写一个测试程序。
<Grid Loaded="onGridLoaded">
<Ellipse Width="300" Height="300" >
<Ellipse.Fill>
<RadialGradientBrush x:Name="rdGradientBrush" Center="0.5, 0.5"
RadiusX="0.5" RadiusY="0.5">
<GradientStop Color="LightGreen" Offset="0"/>
<GradientStop Color="DarkGreen" Offset="1"/>
</RadialGradientBrush>
</Ellipse.Fill>
</Ellipse>
<Grid.Resources>
<Storyboard x:Name="std">
<ColorAnimationUsingKeyFrames Duration="0:0:6"
RepeatBehavior="Forever"
Storyboard.TargetName="rdGradientBrush"
Storyboard.TargetProperty="(RadialGradientBrush.GradientStops)[0].(GradientStop.Color)">
<LinearColorKeyFrame KeyTime="0:0:1" Value="Orange"/>
<LinearColorKeyFrame KeyTime="0:0:3" Value="White"/>
<LinearColorKeyFrame KeyTime="0:0:6" Value="Pink"/>
</ColorAnimationUsingKeyFrames>
<ColorAnimationUsingKeyFrames Duration="0:0:6"
RepeatBehavior="Forever"
Storyboard.TargetName="rdGradientBrush"
Storyboard.TargetProperty="(RadialGradientBrush.GradientStops)[1].(GradientStop.Color)">
<LinearColorKeyFrame KeyTime="0:0:3" Value="Yellow"/>
<LinearColorKeyFrame KeyTime="0:0:6" Value="Violet"/>
<LinearColorKeyFrame KeyTime="0:0:7" Value="SeaGreen"/>
</ColorAnimationUsingKeyFrames>
</Storyboard>
</Grid.Resources>
</Grid>
页面上的正圆是使用径向渐变填充的,渐变颜色点有两个,我们分别对这两个渐变点的颜色进行线性动画处理,这样就会做出很漂亮的效果,如下面图片所示。
分享到:
相关推荐
windows phone 开发 在线教程
Developers are racing to discover how to develop for Windows Phone 7—and there is no quicker resource to help you get up to speed than Windows Phone 7 Recipes. This book covers all aspects of ...
本书旨在分享强大的Microsoft编程工具(诸如Silverlight、XNA和Visual Studio 2010 Express Edition一类)的使用心得,介绍了如何使用现有的C#和.NET编程技能来开发一些Windows Phone 7应用程序。本书作者团队探讨了...
iPhone帧动画 一个连帧动画的例子 由开始和暂停2个按键控制
windows phone 开发书籍及资料
windowsphone开发:类库和案例[借鉴].pdf
在开发Windows Phone应用程序的时候,或多或少会与图片打交道,下面总结下Windows Phone 中处理图片的一些技巧
对游戏场景和游戏菜单、2D动画和纹理处理、精灵的矢量移动和控制、战斗和魔法系统、关卡设计和AI系统、音效处理和文本处理、游戏优化等这些在游戏开发中遇到的实际问题进行了详细的分析和解答,并对XNA主流框架和...
本书系统论述了Windows Phone 7操作系统的应用开发,全书由浅入深地介绍了Windows Phone 7应用程序开发的各方面知识,分为开发基础篇、开发技术篇和开发实例篇3个部分,从不同的层面进行了阐释。开发基础篇介绍了...
Windows Phone(简称:WP)是微软发布的一款手机操作系统,它将微软旗下的Xbox Live游戏、Xbox Music音乐与独特的视频体验集成至手机中。微软公司于2010年10月11日晚上9点30分正式发布了智能手机操作系统Windows ...
iphone帧动画的播放
Windows Phone开发-XNA基础
WindowsPhone开发,包含聊天室案例开始,阅读器、天气预报、SignalR
[Packt Publishing] Windows Phone 8 游戏开发教程 (英文版) [Packt Publishing] Windows Phone 8 Game Development (E-Book) ☆ 图书概要:☆ A practical guide to creating games for the Windows Phone 8 ...
(10):Windows Phone 中处理图片的技巧 (11):让StackPanel中的控件靠右对齐 (12):让你的Windows Phone应用变得更Metro (13):自定义Element Binding (14):输入框隐藏SIP事件 。。。。。
第三章 Windows Phone 7 广告服务应用 - AdMob 篇 第四章 Silverlight for Windows Phone 7: Hello Windows Phone 7 第五章 当 Windows Azure 碰到了 Windows Phone 7 推送通知服务概述 Silverlight 交互开发: 第...
从monotouch和.net开发环境到objective-c和c#开发语言,从基于monotouch进行iphone开发的编程方法到应用程序的发布和销售等,《iPhone高级编程:使用Mono Touch和.NET/C#》涵盖了基于monotouch进行iphone应用程序...
Windows Phone7是微软重新打造windows mobile品牌之后推出的一款产品。
仿Windows Phone博客导航源码 程序介绍: Windows Phone Blog Menu是一个Silverlight导航控件,看起来像Windows Phone 7。 控件中的tiles链接到web站点在你的博客中使用这个控件可以表达你对WP7的喜爱。 Windows...
windows phone7 开发的案例,内有完整的工程项目。