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

本文介绍如何使用C#和XAML实现文本的色彩渐变动画效果,通过定时器逐步改变渐变停止点的位置,使文本颜色从红色平滑过渡到绿色。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

            环   境:  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#中进行操作,达到控制的效果。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

苍穹0113

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值