• [T1 Silverlight Training] Day 2: Mouse & Keyboard (Routed Event), Animation(Linear Animation, Key Frame, StoryBoard)


    "一个月一更么?",呵呵,最近太忙了,没机会写博客,现在补上。

    首先,我还是想Show一下我和Andy Wigley的合影,相信大家都知道Jump Start Video的Presenter吧,这次去西雅图带回来很多有用的WP7资源,在T2的时候再介绍。

    【插播广告】我们在北京招聘Windows Phone 7 Architect,有意向的人请联系我 linuszhu@gmail.com

    Mouse & Keyboard (Routed Event)

    鼠标和键盘事件和普通的Windows Form应用程序或者Asp.net应用程序的事件没有差别,在WP中也保留了Silverlight的Mouse事件,不过同时也映射到了Tap等Touch相关的事件。

    对于Silverlight应用程序的鼠标或者键盘事件都是Routed Event,和普通的Event差别在于,能够进行在UI的Visual Tree上进行Bubble,同时EventArgs上带有OriginalSource来标识该事件最先发起的对象。

    Animation(Linear Animation, Key Frame, StoryBoard)

    Animation我觉得是在Silverlight里面非常强大的东西,关键的是在于它有很好的工具Blend支持。关于工具,这是我在给Symbian的人培训的时候大家得出的一个主要结论,微软在语言、框架、理念上并领先,甚至有些Qt的更好,但在工具上绝对是胜出一大截,这个也可以理解,因为微软的目的就是让程序员"傻瓜化"(不知道是好事还是坏事)。

    在Silverlight里面总结一句话,什么是Animation?

    Animation随着时间的变化来改变Dependency Property值。

    Animation有以下三个主要的概念

    • Storyboard, 动画控制单元,通过名称来找到相应的动画,包含Play,Stop等方法
    • Timeline, 动画制作主线,主要有DoubleAnimation,PointAnimation,ColorAnimation等,通过StoryBoard的Target和TargetProperty Attach Property来设置该动画效果针对哪个具体的Logical Tree UIElement
    • Key frame, 动画帧,即某时刻某个DP的属性值应该为多少,主要有LinearDoubleKeyFrame, DiscreteDoubleKeyFrame, SplineDoubleKeyFrame, EasingDoubleKeyFrame

    以下给出了一些Animation的实例

    <Storyboard x:Name="drive" Storyboard.TargetName="car">

    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(Canvas.Left)">

    <LinearDoubleKeyFrame KeyTime="0:0:2" Value="100"/>

    <LinearDoubleKeyFrame KeyTime="0:0:4" Value="100"/>

    <LinearDoubleKeyFrame KeyTime="0:0:6" Value="200"/>

    </DoubleAnimationUsingKeyFrames>

    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(Canvas.Top)">

    <LinearDoubleKeyFrame KeyTime="0:0:2" Value="0"/>

    <LinearDoubleKeyFrame KeyTime="0:0:4" Value="50"/>

    </DoubleAnimationUsingKeyFrames>

    </Storyboard>

    DoubleAnimation animation = new DoubleAnimation();

    animation.From = 0;

    animation.To = 100;

    animation.Duration = new Duration(new TimeSpan(0,0,2));

    Storyboard storyboard = new Storyboard();

    Storyboard.SetTarget (animation, ball);

    Storyboard.SetTargetProperty(animation, new PropertyPath( "(Canvas.Left)" ));

    对于非线性的动画可以通过Spline的两个Control Point来控制AP值变化速率,可以通过Blend来进行设置。

    同时Silverlight也自带了一系列的预先配置好的Timeline效果,称作EasingFunction,可以直接使用。

    最后还有一点要提一下,由于WP7的StoryBoard是运行在Composite Thread上面,而该线程可以直接通过GPU进行绘画,因此动画效果会很好,如果大家涉及到将某个UIElement的属性(所有属性均为DP)随着时间变化时,首先考虑用的应该就是Animation。

    下篇

    Day 3 : Data Binding(Code, XAML, Value Conversion, Collection), Networking (Http, Socket)

  • 相关阅读:
    理解Python的With语句
    python按行读取文件,如何去掉换行符" "
    如何使用科大 mirrors 加速 pip?
    python os.path模块常用方法详解
    Python ConfigParser的使用
    mono-project
    Ubuntu 15.04下MySQL 5.6.25不支持中文解决办法
    ubuntu 15.04开放mysql远程连接
    在Linux(Ubuntu/openSUSE/CentOS)下配置ASP.NET(Apache + Mono)转载+补充
    Asp.net MVC @Html.DisplayNameFor中文乱码解决办法
  • 原文地址:https://www.cnblogs.com/linuszhu/p/T1_Day2_Silverlight_Event_Animation.html
Copyright © 2020-2023  润新知