歌詞滾動效果在Win8 Store 開發中的實現

來源:互聯網
上載者:User
            環   境:  Windows 8 32位 企業版     開發工具: Visual Studio Express 2012 for Windows 8           語    言: C# XAML     技    術: 色彩漸層                                  XAML 代碼設定:

 <TextBlock Text="你是我的眼" FontSize="45" Height="200" Width="500" >

            <TextBlock.Foreground>

                <LinearGradientBrush>

                    <GradientStop Color="Red" Offset="0"></GradientStop>

                    <GradientStop x:Name="gs1" Color="Red"Offset="0"></GradientStop>

                    <GradientStop x:Name="gs2" Color="Green"Offset="0"></GradientStop>

                    <GradientStop Color="GreenOffset="1"></GradientStop>

                </LinearGradientBrush>

            </TextBlock.Foreground>

        </TextBlock>

    


    C#代碼設定:

 protected override void OnNavigatedTo(NavigationEventArgs e)

        {

            DispatcherTimer timer = new DispatcherTimer();  //建立定時器

            timer.Interval = TimeSpan.FromMilliseconds(200);    //設定間隔為0.2

            timer.Tick+=timer_Tick;

            timer.Start();     //開啟定時器

        }

        void timer_Tick(object sender, object e)

        {

            gs1.Offset += 0.05;

            gs2.Offset += 0.05;

        }



   運行效果:




    其中的x:Name屬性類似於附加屬性,GradientStop本來沒有Name屬性,所以在XAML中用上面形式附加屬性,便於在C#中進行操作,達到控制的效果。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.