Edit

Share via


Label

Label controls usually provide information in the user interface (UI). Historically, a Label has contained only text, but because the Label that ships with Windows Presentation Foundation (WPF) is a ContentControl, it can contain either text or a UIElement.

Screenshot of Label controls displayed in different ways.

A Label provides both functional and visual support for access keys. It's frequently used to enable quick keyboard access to controls such as a TextBox. To assign a Label to a Control, set the Label.Target property to the control that should get focus when the user presses the access key.

The following image shows a Label "Theme" that targets a ComboBox. When the user presses T, the ComboBox receives focus.

Title Description
How to: Create a Control That Has an Access Key and Text Wrapping Learn how to create a control that has an access key and supports text wrapping.

Styles and templates

This section describes the styles and templates for the Label control. You can modify the default ControlTemplate to give the control a unique appearance. For more information, see What are styles and templates? and How to create a template for a control.

Content property

The Label control uses the Content property to display its content. This property can contain text or any UIElement.

Parts

The Label control doesn't define any template parts.

Visual states

The following table lists the visual states for the Label control.

VisualState Name VisualStateGroup Name Description
Valid ValidationStates The control uses the Validation class and the Validation.HasError attached property is false.
InvalidFocused ValidationStates The Validation.HasError attached property is true and the control has focus.
InvalidUnfocused ValidationStates The Validation.HasError attached property is true and the control doesn't have focus.

See also