什么是行为(Behaviors)
【From jv9】
在开始学习前,首先需要了解一下Behaviors(行为)的几个关键点:
(1)Behaviors(行为)是可复用代码集合,可以被任何对象附加使用;
(2)设计人员和开发人员可以使用Behaviors(行为)在不用设计任何代码的情况下,添加相关功能到XAML中;
(3)Behaviors(行为)可以通过XAML附加到任何对象元素中,无需设计任何后台代码;
(4)一个Behaviors(行为)可以被多个对象同时调用;
我们可以在Expression Blend中在不必编写代码的情况下向应用程序添加交互性,将行为从"资产"面板拖到应用程序中的对象上,然后设置该行为的属性。
Expression Blend给我们预定义了一些常用的行为:如调用方法行为、控制故事板行为、超链接行为等等。
<a target="_blank" href="http://blog.51cto.com/attachment/201105/222716298.jpg"></a>
我们也可以点击Expression Gallery到官方网站需找新有的行为
<a target="_blank" href="http://blog.51cto.com/attachment/201105/171436653.jpg"></a>
打开项目,首先我们先创建一个简单的动画,命名为showColorAnimation
<a target="_blank" href="http://blog.51cto.com/attachment/201105/222914470.jpg"></a>
在时刻0.5 时,我们将矩形旋转45度
<a target="_blank" href="http://blog.51cto.com/attachment/201105/222946498.jpg"></a>
在时刻1秒时,旋转为135度
<a target="_blank" href="http://blog.51cto.com/attachment/201105/223014807.jpg"></a>
最后在1.5秒时刻旋转度数为180度,停止录制动画。开始向RadioButton添加Action了。切换到Asset卡片,选择ControlStoryboadAction用来控制动画的播放
<a target="_blank" href="http://blog.51cto.com/attachment/201105/223041482.jpg"></a>
将其拖动到rbRed上,命名为redAction
<a target="_blank" href="http://blog.51cto.com/attachment/201105/223111993.jpg"></a>
修改行为的一些属性
<a target="_blank" href="http://blog.51cto.com/attachment/201105/223140548.jpg"></a>
对rbGreen、rbBlue做相同的行为
<a target="_blank" href="http://blog.51cto.com/attachment/201105/223221124.jpg"></a>
按F5运行程序,最后的运行效果如下
<a target="_blank" href="http://blog.51cto.com/attachment/201105/223246212.jpg"></a>
<a target="_blank" href="http://alexis.blog.51cto.com/attachment/201105/2621421_1306247618.rar"></a>
<a href="http://down.51cto.com/data/2358178" target="_blank">附件:http://down.51cto.com/data/2358178</a>
本文转自xshf12345 51CTO博客,原文链接:http://blog.51cto.com/alexis/572940,如需转载请自行联系原作者