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. < Grid> 
  5. < DockPanel> 
  6. < Button Name="ColorAnmationButton" Width="100" Height="50" 
    Background="LightBlue">Color Anmation< /Button> 
  7. < Label Name="ColorAnimationLabel" Width="200" 
    Height="50" Background="Red"> 
  8. < /Label> 
  9. < /DockPanel> 
  10. < /Grid> 
  11. < /Page> 

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

网页名称:C++实现WPF动画具体操作方法详解
本文地址:http://www.csdahua.cn/qtweb/news5/479855.html

网站建设、网络推广公司-快上网,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 快上网