且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

歌词滚动效果在Win8 Store 开发中的实现

更新时间:2022-08-14 12:47:53

            环   境:  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;

        }



   运行效果:


歌词滚动效果在Win8 Store 开发中的实现


    其中的x:Name属性类似于附加属性,GradientStop本来没有Name属性,所以在XAML中用上面形式附加属性,便于在C#中进行操作,达到控制的效果。