Tuesday 28 May 2013

TextBlock Vs Label

Posted by Rahul at 20:51
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.





If you enjoyed this post and wish to be informed whenever a new post is published, then make sure you subscribe to my regular Email Updates. Subscribe Now!


Kindly Bookmark and Share it:

YOUR ADSENSE CODE GOES HERE

0 comments:

Have any question? Feel Free To Post Below:

 

Popular Posts

Recent Comments

© 2011. All Rights Reserved | Help to know WPF | Template by Blogger Widgets

Home | About | Top