Working with Text Controls

Somewhat surprisingly, Silverlight 2.0 does not ship with the expected ‘Label’ control. However, the TextBlock is
the functional equivalent. The TextBlock can be used whenever you need to define a block of read-only text, via the
Text property.

Beyond a blurb of literal text, the TextBlock type also allows you to define unique segments of configurable text
using the <Run> and <LineBreak> types. Consider the combination of
TextBlock + Run + LineBreak to be a
lightweight ‘rich text box’. Here are a few TextBlock examples, one of which uses a rounded Border object.


<StackPanel Background="White">
<Border BorderBrush="Black" BorderThickness="4" CornerRadius="30">
  <TextBlock TextAlignment="Center" Text="I am a block of read-only text"
             FontSize="20" FontFamily="Ariel"/>
</Border>

<TextBlock TextWrapping="Wrap" TextAlignment="Center">
  <Run FontFamily="Comic Sans MS" FontSize="40" Foreground="Green"
       Text="But I am so much cooler text!"/>   
  <LineBreak/>
  <Run FontFamily="Comic Sans MS" FontSize="30" Foreground="Purple"
       FontStyle="Italic" Text="Me too!"/>   
</TextBlock>
</StackPanel>



















The TextBox control is a UI element which allows the user to enter textual information (names, passwords, etc).
A multiline text box can be simulated by setting the
AcceptsReturn property to true.


<TextBox AcceptsReturn="True" Background="LightBlue" Height="40"
        FontSize="20" FontFamily="Comic Sans MS" />
Text Controls
Table of Contents
Copyright (c) 2008.  Intertech, Inc. All Rights Reserved.  This information is to be used exclusively as an
online learning aid.  Any attempts to copy, reproduce, or use for training is strictly prohibited.
Courseware
Training Resources
Tutorials
Services