WPF實(shí)現(xiàn)左右移動(dòng)(晃動(dòng))動(dòng)畫效果
本文實(shí)例為大家分享了WPF實(shí)現(xiàn)左右移動(dòng)效果展示的具體代碼,供大家參考,具體內(nèi)容如下
實(shí)現(xiàn)控件或布局的左右移動(dòng)(晃動(dòng))主要用到DoubleAnimation以及Storyboard
布局代碼為:
<Canvas> <Grid Width="200" Height="100" Background="MediumAquamarine" Name="GroupboxArea" Canvas.Left="100" Canvas.Top="200"/> <Button Content="Button" Height="25" Width="78" Click="Button_Click"/> </Canvas>
后臺(tái)代碼為:
private void Button_Click(object sender, RoutedEventArgs e) { DoubleAnimation DAnimation = new DoubleAnimation(); DAnimation.From = 100;//起點(diǎn) DAnimation.To = 280;//終點(diǎn) DAnimation.Duration = new Duration(TimeSpan.FromSeconds(0.5));//時(shí)間 Storyboard.SetTarget(DAnimation, GroupboxArea); Storyboard.SetTargetProperty(DAnimation, new PropertyPath(Canvas.LeftProperty)); Storyboard story = new Storyboard(); story.Completed += new EventHandler(story_Completed);//完成后要做的事 //story.RepeatBehavior = RepeatBehavior.Forever;//無限次循環(huán),需要的自己加上 story.Children.Add(DAnimation); story.Begin(); } void story_Completed(object sender, EventArgs e) { DoubleAnimation DAnimation = new DoubleAnimation(); DAnimation.From = 280;//起點(diǎn) DAnimation.To = 100;//終點(diǎn) DAnimation.Duration = new Duration(TimeSpan.FromSeconds(0.5));//時(shí)間 Storyboard.SetTarget(DAnimation, GroupboxArea); Storyboard.SetTargetProperty(DAnimation, new PropertyPath(Canvas.LeftProperty)); Storyboard story = new Storyboard(); story.Completed += new EventHandler(storyCompleted);//完成后要做的事 //story.RepeatBehavior = RepeatBehavior.Forever;//無限次循環(huán),需要的自己加上 story.Children.Add(DAnimation); story.Begin(); } void storyCompleted(object sender, EventArgs e) { DoubleAnimation DAnimation = new DoubleAnimation(); DAnimation.From = 100;//起點(diǎn) DAnimation.To = 200;//終點(diǎn) DAnimation.Duration = new Duration(TimeSpan.FromSeconds(0.5));//時(shí)間 Storyboard.SetTarget(DAnimation, GroupboxArea); Storyboard.SetTargetProperty(DAnimation, new PropertyPath(Canvas.LeftProperty)); Storyboard story = new Storyboard(); //story.Completed += new EventHandler(storyCompleted);//完成后要做的事 //story.RepeatBehavior = RepeatBehavior.Forever;//無限次循環(huán),需要的自己加上 story.Children.Add(DAnimation); story.Begin(); }
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
asp.net 在global中攔截404錯(cuò)誤的實(shí)現(xiàn)方法
asp.net 在global中攔截404錯(cuò)誤,增加用于體驗(yàn),不會(huì)因?yàn)樘崾菊也坏叫畔⒍苯油顺龅膶擂巍?/div> 2010-03-03ASP.NET設(shè)計(jì)FTP文件上傳的解決方案
這篇文章主要介紹了ASP.NET設(shè)計(jì)FTP文件上傳的解決方案,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2015-09-09通過ASP.net實(shí)現(xiàn)flash對(duì)數(shù)據(jù)庫的訪問
近來網(wǎng)站需要在flash中提取數(shù)據(jù)庫中的數(shù)據(jù),從網(wǎng)上找了一點(diǎn)資料,今天下午在自己的機(jī)器上實(shí)現(xiàn)了一下,還是比較簡單的。2009-08-08ASP.NET站點(diǎn)導(dǎo)航應(yīng)用詳解
這篇文章主要內(nèi)容是ASP.NET站點(diǎn)導(dǎo)航,主要包括站點(diǎn)導(dǎo)航以及動(dòng)態(tài)修改內(nèi)存中的站點(diǎn)地圖,感興趣的小伙伴們可以參考一下2015-09-09ubuntu16.4下用jexus部署ASP.NET Core環(huán)境
這篇文章主要以圖文結(jié)合的方式介紹了ubuntu16.4下ASP.NET Core部署環(huán)境搭建步驟,感興趣的小伙伴們可以參考一下2016-07-07如何給asp.net core寫個(gè)中間件記錄接口耗時(shí)
這篇文章主要給大家介紹了關(guān)于如何給asp.net core寫個(gè)中間件記錄接口耗時(shí)的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用asp.net core具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2019-09-09Asp.net 頁面調(diào)用javascript變量的值
開發(fā)過程中碰到了這種情況,我想將javascript中定義的變量賦值給頁面中的TextBox控件.2009-12-12最新評(píng)論