C++实现WPF动画具体操作方法详解

开发 后端
我们今天以一段代码示例为大家详细解读了C++实现WPF动画的具体操作方法,希望大家可以以此为参考对象,来熟练掌握这一应用技巧。

C++编程语言的应方式非常广泛,可以帮助我们轻松的实现许多功能需求。比如今天为大家介绍有关C++实现WPF动画的相关操作,就可以以一种简单的方式来实现。下面就让我们一起来看看具体的操作方法吧。#t#

很多人都习惯使用Blend来帮助编辑XAML文件,生成很多动画。但在实际开发中,用代码来实现动画还是很实用的,而且代码的逻辑开发能力更强,更容易控制,这方面C#的例子已经很多了,下面我介绍几个C++实现WPF动画的例子。

首先介绍少渐隐渐现,也就是Alpha Animation。C++实现WPF动画代码如下

  1. /**//*  
  2. * Take Label for example  
  3. */  
  4. // 1, Find the lable by its name, The name define in the xaml file  
  5. Label^ pColorLabel = (Label^)page->FindName("ColorAnimationLabel");  
  6. // 2, Define a DoubleAnimation object  
  7. DoubleAnimation^ pDoubleAnimation = gcnew DoubleAnimation();  
  8. // 3, Set from to and duration  
  9. pDoubleAnimation->From = 1;  
  10. pDoubleAnimation->To = 0;  
  11. pDoubleAnimation->DurationDuration = Duration(TimeSpan::FromSeconds(3));  
  12. // 4, Create a storyboard(Timeline)  
  13. Storyboard^ pStoryboard = gcnew Storyboard();  
  14. // 5, Set the DoubleAnimation's target name  
  15. pStoryboard->SetTargetName(pDoubleAnimation, _T("ColorAnimationLabel"));  
  16. // 6, Set the DoubleAnimation's property  
  17. pStoryboard->SetTargetProperty(pDoubleAnimation, 
    gcnew PropertyPath(Label::OpacityProperty));  
  18. // 7, Add the DoubleAnimation object to the storyboard  
  19. pStoryboard->Children->Add(pDoubleAnimation);  
  20. // 8, Start the animation  
  21. pStoryboard->Begin(pColorLabel); 

上面C++实现WPF动画代码所用的XAML如下

  1. < Page 
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
  4. > 
  5. < Grid> 
  6. < DockPanel> 
  7. < Button Name="ColorAnmationButton" Width="100" Height="50" 
    Background="LightBlue">Color Anmation< /Button> 
  8. < Label Name="ColorAnimationLabel" Width="200" 
    Height="50" Background="Red"> 
  9. < /Label> 
  10. < /DockPanel> 
  11. < /Grid> 
  12. < /Page> 

以上就是对C++实现WPF动画的相关操作介绍。

责任编辑:曹凯 来源: 博客园
相关推荐

2010-02-03 13:26:53

C++计时

2010-02-02 13:57:31

C++解析#pragm

2010-02-02 17:13:35

C++ Endian

2009-12-30 16:48:52

Silverlight

2010-04-02 08:42:32

Oracle 游标

2010-02-01 14:33:05

C++实现RTTI

2010-01-27 18:00:57

Android开机自启

2010-01-28 16:14:33

Android安装卸载

2010-01-07 15:37:35

VB.NET ForNext循环

2010-03-05 15:27:06

Python文件路径

2010-04-13 17:00:27

Oracle NLS_

2009-12-31 15:36:13

SilverLight

2009-12-31 15:36:13

SilverLight

2010-03-19 14:19:58

Python正则表达式

2010-02-04 11:23:25

C++反射机制

2010-03-24 10:06:37

Python嵌入C++

2010-03-05 17:06:26

Python显示UTF

2010-02-03 09:59:42

C++文件流操作

2009-12-28 16:10:38

WPF生成文件

2010-02-01 17:02:53

C++产生随机数
点赞
收藏

51CTO技术栈公众号