wp7中Storyboard的樣本動畫

來源:互聯網
上載者:User

假如要實現這樣一種控制項,它的透明度由0平滑過渡到1,再由1平滑過渡到0(也就是忽明忽暗的閃爍效果)。

一種方法是定義一個定時器,重複的改變它的透明度。

一種方法則是可以通過storyboard來實現這種閃爍效果,代碼實現起來更為簡潔,代碼如下:

        private Storyboard PrepareShowStory()        {            Storyboard story = new Storyboard();            DoubleAnimation animation;            animation = new DoubleAnimation();            animation.From = 0;            animation.To = 1;            animation.Duration = new Duration(TimeSpan.FromMilliseconds(Duration));            Storyboard.SetTarget(animation, MyTestImage);            Storyboard.SetTargetProperty(animation, new PropertyPath("(UIElement.Opacity)"));            story.Children.Add(animation);            story.AutoReverse = true;            story.RepeatBehavior = RepeatBehavior.Forever;            return story;        }

要開始動畫,可以這樣設定:

m_StoryBoard = PrepareShowStory();m_StoryBoard.Begin();

要暫停動畫,可以這樣:

m_StoryBoard.Pause();

要重新運行動畫,則可以:

m_StoryBoard.Resume();

要結束動畫,則可以:

m_StoryBoard.Stop();

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.