Applying Image in TextBlock Foreground in XAML Silverlight


Introduction

So far we only learn how to apply color in foreground of TextBlock but in this post you will learn how to apply image instead of color. Applying images as foreground looks much attractive than simple color. Gradient will be also one option here instead of image but sometimes images also plays good role. Ok…then let’s begin to use image in foreground of TextBlock.

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

To use image in foreground we use 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 image, use 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>


Comments

Popular posts from this blog

Customize User's Profile in ASP.NET Identity System

Lambda two tables and three tables inner join code samples