Search
Author
ASP.NET Tutorials
Author
Sheo Narayan
Latest Articles
Winners

Win Prizes

Social Presence
Like us on Facebook

Silverlight Tutorials | Report a Bug in the Tutorial
Silverlight TextBlock element tutorials
Silverlight supports TextBlock that allows you to place text into your Silverlight objects.
 
DEMO : TextBlock element Show Source Code
To simply write any text inside the Silverlight object, you need to specify the Text property of the TextBlock element.
<Canvas 
    xmlns="http://schemas.microsoft.com/client/2007" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <TextBlock Text="DotNetFunda.com" />
</Canvas>                 
                    
Common properties of TextBlock element
FontSize allows you to specify the font size of the text.
FontFamily allows you to specify the font names, separated by comma. If the 1st couldn't find, Silverlight will render the text in next font.
FontStyle> allows you to specify the style of the text.
FontWeight allows you to specify the weight of the text.
FontStretch allows you to specify the stretch pattern of the text.
Foreground allows you to specify the color of the text.
Opacity allows you to specify the alpha or transparency of the text.
<Canvas 
    xmlns="http://schemas.microsoft.com/client/2007" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <TextBlock FontSize="20" FontFamily="Arial, Verdana"
      FontStyle="Oblique" FontWeight="Bold" Canvas.Top="20" Canvas.Left="20"
       FontStretch="ExtraCondensed" Foreground="Red" Opacity=".5" >
        DotNetFunda.com
  </TextBlock>
 </Canvas>
                    
Run / LineBreak
Runelement allows you to change the look of specific text inside the TextBlock.
LineBreak allows you to place the text into next line. New line text can be specified inside Run element, otherwise TextBlock properties will be applied to the text.
<Canvas 
    xmlns="http://schemas.microsoft.com/client/2007" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <TextBlock FontSize="15" FontFamily="Arial, Verdana" Canvas.Left="5"
              FontStyle="Oblique" FontWeight="Bold" Canvas.Top="20"
               FontStretch="ExtraCondensed" Foreground="Red" Opacity=".75" >
    Silverlight <Run FontSize="25" Foreground="Blue" FontStyle="Normal">Tutorials</Run>
    <LineBreak />
    <Run FontFamily="Trebuchet MS, Arial" Foreground="Blue" 
        FontStyle="Normal" FontWeight="Thin">
         written by 
        </Run>
        Sheo Narayan
      </TextBlock>
  </Canvas>