Infosys Microsoft Alliance and Solutions blog

« Windows XP SP3 | Main | Office 2007 - Word has stopped working ! »

WPF Label or TextBlock

Pre WPF days just had a Label control and hence there wasn't really a choice. Now in WPF you have Label and a new TextBlock control. I have been wondering on usually which one to use in the application when i hit upon this interesting comparison between the two by Josh. There is one additional difference mentioned in comments down below on that blog that talk about auto inversion of colors for TextBlock if it is part of say a ListItem. However to me it looked more like setting the Foreground to white, since when i tried with styling the item selection color to something else, the TextBlock still showed white color.

Honestly I am now left more confused. TextBlock is light weight and hence good from app performance perspective, but Label gives the access key functionality, something that people prefer to have in their applications. It will be really good to have this functionality extended to TextBlock.

What is it that you use in your applications and why? Comments welcome. 

Comments

We are still in the pre-WPF days and using Label :) One of my colleagues who is using WPF in his projects is using Label. He is not aware of the performance incentive of using TextBlock!

Vijay, thanks for sharing. In pre-WPF days Label was really the only option available. In WPF one now has to pick between Label and TextBlock and it would be interesting to note how people make their choices

There is a big trade-offs in selecting the one of the Two controls.
1.TextBlock is derived from FrameworkElement
2.Label is derived from System.Windows.Control
3.If we go more down, TextBlock is lightweight.
4.TextBlock doesnot have link to other controls as Target.
6.The important usage Advantage is when you want to display text use TextBlock.
7.when you want to associate with other control like TextBox, use Label.
8.TextBlock has no support Access keys.
9.

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

Please key in the two words you see in the box to validate your identity as an authentic user and reduce spam.

Subscribe to this blog's feed

Follow us on

Blogger Profiles

Infosys on Twitter