IOT Virtual Conference - Register now to book your ticket and get updates
x
CONGRATULATIONS! C# Corner Q1, 2021 MVPs Announced
Why Join
Become a member
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
TECHNOLOGIES
ANSWERS
LEARN
NEWS
BLOGS
VIDEOS
INTERVIEW PREP
BOOKS
EVENTS
CAREER
MEMBERS
JOBS
WPF: Textblock Vs Label
Nipun Tomar
Updated date
Aug 12, 2012
73.7
k
0
1
In WPF both textblock and level are used to show a small amount of text means
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
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