C++实现WPF动画具体操作方法详解
C++编程语言的应方式非常广泛,可以帮助我们轻松的实现许多功能需求。比如今天为大家介绍有关C++实现WPF动画的相关操作,就可以以一种简单的方式来实现。下面就让我们一起来看看具体的操作方法吧。
很多人都习惯使用Blend来帮助编辑XAML文件,生成很多动画。但在实际开发中,用代码来实现动画还是很实用的,而且代码的逻辑开发能力更强,更容易控制,这方面C#的例子已经很多了,下面我介绍几个C++实现WPF动画的例子。
首先介绍少渐隐渐现,也就是Alpha Animation。C++实现WPF动画代码如下
/**//* * Take Label for example */ // 1, Find the lable by its name, The name define in the xaml file Label^ pColorLabel = (Label^)page->FindName("ColorAnimationLabel"); // 2, Define a DoubleAnimation object DoubleAnimation^ pDoubleAnimation = gcnew DoubleAnimation(); // 3, Set from to and duration pDoubleAnimation->From = 1; pDoubleAnimation->To = 0; pDoubleAnimation->DurationDuration = Duration(TimeSpan::FromSeconds(3)); // 4, Create a storyboard(Timeline) Storyboard^ pStoryboard = gcnew Storyboard(); // 5, Set the DoubleAnimation's target name pStoryboard->SetTargetName(pDoubleAnimation, _T("ColorAnimationLabel")); // 6, Set the DoubleAnimation's property pStoryboard->SetTargetProperty(pDoubleAnimation, gcnew PropertyPath(Label::OpacityProperty)); // 7, Add the DoubleAnimation object to the storyboard pStoryboard->Children->Add(pDoubleAnimation); // 8, Start the animation pStoryboard->Begin(pColorLabel);
上面C++实现WPF动画代码所用的XAML如下
相关推荐
maokaijiang 2020-06-14
<!-- Row 0 -->. <TextBlock Text="{Binding Department, ElementName = window}". <!-- Row 1 -->. <TextB
Laxcus大数据技术 2020-05-27
wndong 2020-05-20
88473166 2020-05-14
89427412 2020-05-06
conganguo 2020-05-06
86523296 2020-04-22
QCkiss 2020-04-17
VanTYS 2020-02-23
89427412 2020-02-13
seekerhit 2020-01-24
Streamoutput 2020-01-21
teliduxing0 2020-01-14
conganguo 2020-01-18
ixshells 2020-01-14
檀木雨林 2020-01-10
86523296 2020-01-08