Export (0) Print
Expand All
0 out of 7 rated this helpful - Rate this topic

Label Class

Updated: February 2009

Represents the text label for a control and provides support for access keys.

Namespace:  System.Windows.Controls
Assembly:  PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
[LocalizabilityAttribute(LocalizationCategory.Label)]
public class Label : ContentControl
<Label>
  Content
</Label>

This class provides both functional and visual support for access keys (also known as mnemonics). It is frequently used to enable quick keyboard access to controls such as a TextBox. To assign a Label to a Control, set the Target property to the control that should get focus when the user presses the access key. Setting the target also causes Microsoft UI Automation to use the text of the label as the name of the targeted control. For more information, see Accessibility.

To set the access key, add an underscore before the character that should be the access key. If your content has multiple underscore characters, only the first one is converted into an access key; the other underscores appear as normal text. If the underscore that you want converted to the access key is not the first underscore, use two consecutive underscores for any underscores that precede the one that you want to convert. For example, the following code contains an access key and displays as _HelloWorld:

<Label>__Hello_World</Label> 

Because the underscore that precedes H is a double, the W key registers as the access key.

A label is not focusable, and it is not a tab stop. For details, see Focus Overview.

Content Model: Label is a ContentControl. Its content property is Content. For more information on the content model for Label, see Controls Content Model Overview.

Dependency properties for this control might be set by the control’s default style. If a property is set by a default style, the property might change from its default value when the control appears in the application. The default style is determined by which desktop theme is used when the application is running. For more information, see Themes.

The following example shows how to create a Label that uses a binding to set the target.

<TextBox Name="tb" Width="50"/>
<Label Target="{Binding ElementName=tb}">_File</Label>

The following example shows how to create a Label that has an access key and supports text wrapping.

<TextBox Name="textBox1" Width="50" Height="20"/>
<Label Width="200" HorizontalAlignment="Left"
       Target="{Binding ElementName=textBox1}">
  <AccessText TextWrapping="WrapWithOverflow">
    _Another long piece of text that requires text wrapping
    goes here.
  </AccessText>
</Label>
System.Object
  System.Windows.Threading.DispatcherObject
    System.Windows.DependencyObject
      System.Windows.Media.Visual
        System.Windows.UIElement
          System.Windows.FrameworkElement
            System.Windows.Controls.Control
              System.Windows.Controls.ContentControl
                System.Windows.Controls.Label
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0

Date

History

Reason

February 2009

Described how default styles change dependency properties.

Customer feedback.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.