Blue Theme Orange Theme Green Theme Red Theme
 
Home | Forums | ASP.NET 2.0 Tutorials | Web Services | How Do I...? | Class Browser | WPF Quick Starts | Advertise with Us
 | Consulting  
Submit an Article Submit a Blog 
Search :       Advanced Search »
Home » Blogs Home » Blog Detail

TextBlock Control in Silverlight

 by Rohatash Kumar on Nov 23, 2011

Here, we will see how to create and use TextBlock control in Silverlight 4.
Comments: 0 Views: 597 Printable Version 

TextBlock control

TextBlock control allows you to apply effects to your text such as strike-through, shadows and borders. The TextBlock control are used to display the text. This control allows you to render read only text.

Properties - These are the following properties of this control.

  1. The Width property of the TextBlock element represent the width of a TextBlock.
  2. The Height property of the TextBlock element represent the width and the height of a TextBlock.
  3. The Text property of the TextBlock element represents the content of a TextBlock.
  4. The Foreground property sets the foreground color of contents or text.
  5. Margin Gets or sets the outer margin of a TextBlock control.
  6. MaxHeight Gets or sets the maximum height constraint of a TextBlock control.
  7. MaxWidth Gets or sets the maximum width constraint of a TextBlock control.
  8. Opacity Gets or sets the degree of the object's opacity.

Creating a TextBlock

Creating a TextBlock control in XAML.

<TextBlock Height="23" HorizontalAlignment="Left" Margin="10,10,0,0" Name="TextBlock1" Text="Hello, Rohatash" VerticalAlignment="Top" />

There are also a variety of options you can apply to your font.

FontFamily - The font typeface family name.

<TextBlock FontFamily="Courier New">Hello, Rohatash</TextBlock>
<
TextBlock FontFamily="Times New Roman" Canvas.Top="10">Hello, Rohatash</TextBlock>
<TextBlock FontFamily="Verdana" Canvas.Top="20">Hello, Rohatash</TextBlock>

FontSize - The font size is the size in pixels.

<TextBlock FontSize="10">Hello, Rohatash</TextBlock>
<
TextBlock FontSize="20" Canvas.Top="20">Hello, Rohatash</TextBlock>
<TextBlock FontSize="30" Canvas.Top="50">Hello, Rohatash</TextBlock>

FontWeight - FontWeight has the following option. such as Thin, ExtraLight, Light, Normal, Medium, SemiBold, Bold, ExtraBold, Black, ExtraBlack.
 

<TextBlock Text="Hello, Rohatash" FontWeight="Normal"  Canvas.Top="0"></TextBlock>

<TextBlock Text="Hello, Rohatash" FontWeight="Bold"  Canvas.Top="10"></TextBlock>

Foreground - This allows you to change the color of the font.

 

<TextBlock Text="Hello, Rohatash" FontSize="30" FontFamily="Arial" Canvas.Top="0">  <TextBlock.Foreground>

    <LinearGradientBrush>

        <GradientStop Color="#FF0000FF" Offset="0.0" />

        <GradientStop Color="#FFEEEEEE" Offset="1.0" />

      </LinearGradientBrush>

    </TextBlock.Foreground>

        </TextBlock>

        <TextBlock Text="Hello, Rohatash" FontSize="30" FontFamily="Arial" Canvas.Top="20" Foreground="Red" Margin="0,34,0,-34"></TextBlock>

 

TextDecorations - A text decoration is a visual ornament that you can add to text.

<TextBlock TextDecorations="underline"  TextWrapping="Wrap">Hello, Rohatash</TextBlock>

Runs - we can inter-mix different runs of text formatting within the same block using the Run element. For example, you can display a string like this:

<TextBlock Margin="0,12,0,-12">

    <Run FontWeight="Bold">Hello, Rohatash</Run>

    <Run Foreground="Red">How are you?</Run>

    <Run FontStyle="Italic">I am fine thanks!</Run>

    </TextBlock>

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
 
What do you say about this post? Post a comment here
*Title:
*Comment:
 
Comments not available.
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor

 Blogger's Profile
Age: Not Available
Location:
Title: Developer
Joined: Aug 10, 2010
Education: Masters Degree
 More Blogs from this Blogger
No record available
 Latest Blogs
[Video] OnClose Handler
[Video] Storing and Loading the Window and Toolbar position
The Euclidean Algorithm
Swapping Exe Process
How Exe file is Generated by VS2005 C++ Project?
What is Exe
Header files: Multiple Inclusion problem - Solution B
Header files: Multiple Inclusion problem - Solution A
Header files: Multiple Inclusion problem - Reason
Header files: Multiple Inclusion problem
View all »
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 
6 Months Free & No Setup Fees ASP.NET Hosting!
 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.