WPFwiki, wpf, wiki, .net 3.0, windows presentation foundation, FAQ, free resources, solution, development, microsoft Home of the world's largest WPF FAQ
Edit

Category

Controls

Edit

Question

What is the difference between the TextBlock and the Label controls?

Edit

Answer

TextBlock is a class specialized for the display of simple text. In contrast, the Label class participates in what is called the Content Model. The Content Model states that an object should expose a Content property, which can be used to display any kind of content, such as text, images, controls, etc. If you are sure that you simply need to display some simple text, the TextBlock is best suited for your needs. However, if you are not sure, Label should be used. Label also has a "Target" property which is helpful for accessibility.

Label also uses the underscore ("_") character to indicate keyboard accelerators. If a Label's Content is set to the string "_Name", then the Label strips out the "_" and just displays "Name"; but if you press the Alt key, the "N" will be shown underlined, and pressing Alt+N will cause the label's Target control to receive focus. TextBlock doesn't do anything special with underscores, and displays them normally.

All content is Copyright ©2007 Xceed Software Inc. unless otherwise indicated. See the Terms of Service. Contributors must read and agree to the Contribution Policy. WPFwiki is brought to you by Xceed, makers of the powerful yet free Xceed DataGrid for WPF.