使用线性渐变写一个歌词播放效果

静态展示的页面显示

        <TextBlock Text="相信光明就在远方" HorizontalAlignment="Left" Margin="200,200,0,0" FontSize="60">
            <TextBlock.Foreground>
                <LinearGradientBrush>
                    <GradientStop Color="Yellow"></GradientStop>
                    <GradientStop Offset="0.3" Color="Yellow"></GradientStop>
                    <GradientStop Offset="0.3" Color="Blue"></GradientStop>
                    <GradientStop Color="Blue" Offset="1"></GradientStop>
                </LinearGradientBrush>
            </TextBlock.Foreground>
        </TextBlock>

在这里,需要普及一个小常识,在XAML中如果元素有Name属性,Name,x:Name都行,如果没有Name属性,则只能用x:Name,现在我们添加一个定时器使我们的歌词动起来

 <TextBlock Text="相信光明就在远方" HorizontalAlignment="Left" Margin="200,200,0,0" FontSize="60">
            <TextBlock.Foreground>
                <LinearGradientBrush>
                    <GradientStop Color="Yellow"></GradientStop>
                    <GradientStop x:Name="gc1" Offset="0.3" Color="Yellow"></GradientStop>
                    <GradientStop x:Name="gc2"  Offset="0.3" Color="Blue"></GradientStop>
                    <GradientStop Color="Blue" Offset="1"></GradientStop>
                </LinearGradientBrush>
            </TextBlock.Foreground>
        </TextBlock>
  protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            DispatcherTimer timer = new DispatcherTimer();
            timer.Interval = TimeSpan.FromMilliseconds(200);
            timer.Tick += timer_Tick;
            timer.Start();
        }

        private void timer_Tick(object sender, object e)
        {
            gc1.Offset += 0.01;
            gc2.Offset += 0.01;
        }

 

你可能感兴趣的:(使用)