Animation in Windows 8 apps

本文介绍了一个在Windows8应用中实现动画效果的具体示例。通过使用Storyboard类及各种动画属性,如DoubleAnimation,可以平滑地改变UI元素的位置、大小等属性。示例代码展示了如何设置动画的时间间隔、起始位置和结束位置。

在Windows 8 App里边的动画和在silverlight里边还有稍微的区别, 如代码:

using Windows.UI.Xaml;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Animation;
using Windows.UI.Xaml.Controls;

        protected void DemoAnimation()
        {
            Duration m_Dur = new Duration(TimeSpan.FromSeconds(4));
            Storyboard sb = new Storyboard();
            sb.Duration = m_Dur;

            DoubleAnimation topAnimation = new DoubleAnimation();
            topAnimation.Duration = m_Dur;
            DoubleAnimation leftAnimation = new DoubleAnimation();
            leftAnimation.Duration = m_Dur;

            Storyboard.SetTarget(topAnimation, myPictureCanvas);
            Storyboard.SetTargetProperty(topAnimation, "(Canvas.Top)");
            Storyboard.SetTarget(leftAnimation, myPictureCanvas);
            Storyboard.SetTargetProperty(leftAnimation, "(Canvas.Left)");
            topAnimation.EnableDependentAnimation = true;
            leftAnimation.EnableDependentAnimation = true;
            topAnimation.From = 0;
            leftAnimation.From = 0;
            topAnimation.To = 500;
            leftAnimation.To = 500;


            DoubleAnimation heightAnimation = new DoubleAnimation();
            heightAnimation.Duration = m_Dur;
            DoubleAnimation widthAnimation = new DoubleAnimation();
            widthAnimation.Duration = m_Dur;

            Storyboard.SetTarget(heightAnimation, myPictureCanvas);
            Storyboard.SetTargetProperty(heightAnimation, "(Canvas.Height)");
            Storyboard.SetTarget(widthAnimation, myPictureCanvas);
            Storyboard.SetTargetProperty(widthAnimation, "(Canvas.Width)");
            heightAnimation.EnableDependentAnimation = true;
            widthAnimation.EnableDependentAnimation = true;
            heightAnimation.From = 50;
            widthAnimation.From = 50;
            heightAnimation.To = 500;
            widthAnimation.To = 500;
            sb.Children.Add(heightAnimation);
            sb.Children.Add(widthAnimation);

            sb.Children.Add(topAnimation);
            sb.Children.Add(leftAnimation);
            sb.Begin();
        }

 

转载于:https://www.cnblogs.com/qixue/archive/2013/01/11/2856579.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值