和其他控件一样用渐变画刷设置
这是上下渐变
<TextBlock Height="36" HorizontalAlignment="Left" Text="文字前景颜色测试!" VerticalAlignment="Top" Width="230" FontSize="24"> <TextBlock.Foreground> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FF176BCF" Offset="0.022"/> <GradientStop Color="Red" Offset="1"/> </LinearGradientBrush> </TextBlock.Foreground> </TextBlock>
这是左右渐变
<TextBlock Height="36" HorizontalAlignment="Left" Text="文字前景颜色测试!" VerticalAlignment="Top" Width="230" FontSize="24"> <TextBlock.Foreground> <LinearGradientBrush> <GradientStop Color="#FFFF0017"></GradientStop> <GradientStop Color="Green" Offset="0.3"></GradientStop> <GradientStop Color="#FFE820D6" Offset="1"></GradientStop> <GradientStop Color="Blue" Offset="1"></GradientStop> <GradientStop Color="#FF0E7801" Offset="0.283"/> </LinearGradientBrush> </TextBlock.Foreground> </TextBlock>