Silverlight TextBlock Foreground using GradientBrush


In this blog we are going to see how we can using Color TextBlock in Silverlight using Gardient Brush.

Gardient Brush describes a gradient, composed of gradient stops. Classes that derive from GradientBrush describe different ways of interpreting gradient stops.

Lets see the xaml code how we can use the Gradient Brush :

<UserControl x:Class="SilverlightApplication1.MainPage"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

    mc:Ignorable="d"

    d:DesignHeight="300" d:DesignWidth="400">

 

    <Grid x:Name="LayoutRoot" Background="White">

        <TextBlock Text="Silverlight-App" FontSize="18">

            <TextBlock.Foreground>

                <LinearGradientBrush StartPoint="0,0" EndPoint="1,1">

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

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

                </LinearGradientBrush>

            </TextBlock.Foreground>

        </TextBlock>

    </Grid>

</UserControl>

Thats it .   You can run and see the Gradient effect on the TextBlock.

Ebook Download
View all
Learn
View all