Every WPF developer asked himself is why we have Label
and TextBlock controls in WPF When it used.
TextBlock
and Label both are used to display
text.
TextBlock
|
Label
|
Textblock
inherits from FrameworkElement
|
Label
Inherits from System.Windows.Control
|
Lightweight
|
Heavy
Weight control
|
Does
not Supports access key
|
Label supports access key
|
TextBlock
don’t have the IsEnabled Proerty
|
Label’s
IsEnabled property returns false
its text color change into gray
|
Simple
control
|
More
complex control
|
TextBlock
does not have link to other controls as Target
|
It
has a Target property
|
Label
has an important focus handling responsibility. Its purpose is to allow
you to place a caption with an access key. It has a Target property,
which indicates the target of the access key.
Example
<Label Target="{Binding ElementName=name}">User Name:</Label>
<TextBox x:Name="name" />
When
to used label and TextBlock?
When
you want to display text by itself use the TextBlock. The benefit is a light, performing way to display
text.
When you want to associate text
with another control like a TextBox use the Label control. The benefits are
access keys and references to target control.
Comments
Post a Comment