SIGN UP MEMBER LOGIN:    
ARTICLE

Applying Image in TextBlock Foreground in XAML Silverlight

Posted by Abhimanyu Kumar Vatsa Articles | Silverlight with C# May 06, 2011
In this article, you will learn how to apply an image to a TextBlock Foreground.
Reader Level:

Introduction

So far we have only learned how to apply color to the foreground of a TextBlock but in this article you will learn how to apply an image instead of color. Applying images as foreground looks more attractive than simple color. A gradient is another option instead of an image but sometimes images are also a good solution. Ok…then let's begin to use an image for a foreground of a TextBlock.

Refer to the previous posts to learn how to use media in a project. Here we will be using an images directory without talking about the basics.

To use an image as a foreground we use the following code:

<TextBlock Name="txtITORIAN" Text="ITORIAN"

FontSize="150" FontWeight="Bold" FontFamily="Arial">

          <TextBlock.Foreground>

                   <ImageBrush ImageSource="sample.jpg" />

          </TextBlock.Foreground>

</TextBlock>

If you don't wish to apply an image, use the following code:

<TextBlock Name="txtITORIAN" Text="ITORIAN" FontSize="150" FontWeight="Bold"

FontFamily="Arial" Foreground="#FF291CCC">

</TextBlock>

XAML Code

<Grid
         
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"
         
x:Class="SilverlightApplication1.MainPage"
         
Width="640" Height="480">
                  
<TextBlock Name="txtITORIAN" Text="ITORIAN"
                  
FontSize="150" FontWeight="Bold" FontFamily="Arial">
                            
<TextBlock.Foreground>
                                     
<ImageBrush ImageSource="sample.jpg" />
                            
</TextBlock.Foreground>
                  
</TextBlock>
</Grid>

image002.jpg

Be tuned for the next post.

HAVE A HAPPY CODING!!

Login to add your contents and source code to this article
share this article :
post comment
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Nevron Gauge for SharePoint
Become a Sponsor