$title =

Silverlight TextBlock versus Label

;

$content = [

Some thoughts on the use of TextBlock versus Label.

Even though TextBlock lives in the System.Windows.Controls namespace, it is not a control.  It derives directly from FrameworkElement.  Label, on the other hand, derives from ContentControl.  This means that Label can:

1. Be given a custom control template (via the Template property).
2. Display data other than just a string (via the Content property).
3. Apply a DataTemplate to its content (via the ContentTemplate property).
4. Do whatever else a ContentControl can do that a FrameworkElement cannot.

But be aware! The use of Label is a way more heavy then TextBlock due to its Visual Tree.

Visual Tree of a Label:
<Label>
<Border>
   <ContentControl>
     <ContentPresenter>
       <Grid>
         <TextBlock Text="Hello World"/>
       </Grid>
     </ContentPresenter>
   </ContentControl>
</Border>
</Label>

Visual Tree of a TextBlock:
<TextBlock Text="Hello World" />

So unless you really need the functionality provided by a Label (see below) you should use a TextBlock.

 

Happy Coding!
Thomas Martinsen

];

$date =

;

$category =

;

$author =

;