动画教程(动态注册/静态注册)

 1            //实例化StoryBoard
 2             Storyboard storyBoard = new Storyboard();
 3             //设置动画轨迹
 4             DoubleAnimation doubleAnimationY = new DoubleAnimation();
 5             //执行时间
 6             doubleAnimationY.Duration = new Duration(TimeSpan.FromMilliseconds(500));
 7             //变量大小
 8             doubleAnimationY.To = 0;
 9             //绑定执行动画的对象
10             Storyboard.SetTarget(doubleAnimationY, this.Sale(“这个参数是控件对象,也就是说给哪个注册动画”));
11             //设置执行动画的属性
12             Storyboard.SetTargetProperty(doubleAnimationY, new PropertyPath("Height(这个是控件的属性,比如我现在动画的方式改变高度)"));
13             //添加动画
14             storyBoard.Children.Add(doubleAnimationY);
15             //执行动画
16             storyBoard.Begin();

静态注册

 1 <UserControl>
 2     <UserControl.Resources>
 3         <Storyboard x:Name="SlideOut">
 4             <DoubleAnimation Storyboard.TargetName="Slide" Storyboard.TargetProperty="这里的必须是Storyboard.TargetName对象的属性" Duration="00:00:00.50" To="200"/>
 5         </Storyboard>
 6             <Storyboard x:Name="SlideIn">
 7             <DoubleAnimation Storyboard.TargetName="Slide" Storyboard.TargetProperty="这里的必须是Storyboard.TargetName对象的属性" Duration="00:00:00.50" To="0"/>
 8         </Storyboard>
 9     </UserControl.Resources>
10 </UserControl>
11 在事件里面调用
12 SlideIn.Begin();

 

posted @ 2013-03-15 15:18  银河系上的地球  阅读(217)  评论(0编辑  收藏  举报