溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

C++實(shí)現(xiàn)WPF動畫的具體操作方法

發(fā)布時(shí)間:2021-10-27 18:46:25 來源:億速云 閱讀:173 作者:柒染 欄目:編程語言

本篇文章為大家展示了C++實(shí)現(xiàn)WPF動畫的具體操作方法,內(nèi)容簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細(xì)介紹希望你能有所收獲。

C++編程語言的應(yīng)方式非常廣泛,可以幫助我們輕松的實(shí)現(xiàn)許多功能需求。

很多人都習(xí)慣使用Blend來幫助編輯XAML文件,生成很多動畫。但在實(shí)際開發(fā)中,用代碼來實(shí)現(xiàn)動畫還是很實(shí)用的,而且代碼的邏輯開發(fā)能力更強(qiáng),更容易控制,這方面C#的例子已經(jīng)很多了,下面我介紹幾個(gè)C++實(shí)現(xiàn)WPF動畫的例子。

首先介紹少漸隱漸現(xiàn),也就是Alpha Animation。C++實(shí)現(xiàn)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++實(shí)現(xiàn)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> 

上述內(nèi)容就是C++實(shí)現(xiàn)WPF動畫的具體操作方法,你們學(xué)到知識或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識儲備,歡迎關(guān)注億速云行業(yè)資訊頻道。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI