TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
WPF: Textblock Vs Label
Nipun Tomar
Aug 12, 2012
100.2
k
0
1
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
In WPF both textblock and level are used to show a small amount of text means
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)
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.
Next Recommended Reading
WPF Layout: Margin Vs Padding