WPF: Textblock Vs Label


In WPF both textblock and level are used to show a small amount of text means visually both snippets produce the same UI. But there is big difference between the two:

TEXTBLOCK:
TextBlock lives in the System.Windows.Controls namespace, it is not a control. It derives directly from FrameworkElement. TextBlocks are used in a lot of controls to display text.

LABEL:
Label, on the other hand, derives from ContentControl means that label can: be given a custom control template (viaTemplate property), Display data other than just a string (via Content property), Apply a DataTemplate to its content (via ContentTemplate property), and can do whatever else a ContentControl can do that a FrameworkElement cannot. It supports access keys.

Label vs TextBlock (class hierarchy)
Label vs TextBlock (class hierarchy) 

CONCLUSION:


If you want to use styles in WPF correctly (and you need to modify the margin, etc), It is recommend to use a Label instead of a TextBlock. TextBlocks are used inside a lot of controls, and modifying the TextBlock style has a major impact on how most controls (such as a Button, ComboBox, GridView Columns, etc) behave.

So, if you want to display text as a control itself, always use Label. The benefits of showing styles correctly (and have more control over styles and themes) are better than the fact that a TextBlock is lighter.
Ebook Download
View all
Learn
View all
F11Research & Development, LLC