WPF - Label

The Label 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. The hierarchical inheritance of Label class is as follows −
Below are the commonly used properties of Label class
Background
Gets or sets a brush that describes the background of a control. (Inherited from Control.)
Content
Gets or sets the content of a ContentControl. (Inherited from ContentControl.)
ContentStringFormat
Gets or sets a composite string that specifies how to format the Content property if it is displayed as a string.(Inherited from ContentControl.)
ContentTemplate
Gets or sets the data template used to display the content of the ContentControl. (Inherited from ContentControl.)
ContextMenu
Gets or sets the context menu element that should appear whenever the context menu is requested through user interface (UI) from within this element.(Inherited from FrameworkElement.)
FontFamily
Gets or sets the font family of the control. (Inherited from Control.)
FontSize
Gets or sets the font size. (Inherited from Control.)
FontStyle
Gets or sets the font style. (Inherited from Control.)
FontWeight
Gets or sets the weight or thickness of the specified font. (Inherited from Control.)
Foreground
Gets or sets a brush that describes the foreground color. (Inherited from Control.)
Height
Gets or sets the suggested height of the element. (Inherited from FrameworkElement.)
Margin
Gets or sets the outer margin of an element. (Inherited from FrameworkElement.)
Name
Gets or sets the identifying name of the element. The name provides a reference so that code-behind, such as event handler code, can refer to a markup element after it is constructed during processing by a XAML processor. (Inherited from FrameworkElement.)
Resources
Gets or sets the locally-defined resource dictionary. (Inherited from FrameworkElement.)
Style
Gets or sets the style used by this element when it is rendered. (Inherited from FrameworkElement.)
Target
Gets or sets the element that receives focus when the user presses the label's . GTMT
Template
Gets or sets a control template. (Inherited from Control.)
Width
Gets or sets the width of the element. (Inherited from FrameworkElement.)
ContextMenuOpening
Occurs when the system processes an interaction that displays a context menu.
DragEnter
Occurs when the input system reports an underlying drag event with this element as the target. (Inherited from UIElement)
DragLeave
Occurs when the input system reports an underlying drag event with this element as the origin. (Inherited from UIElement)
DragOver
Occurs when the input system reports an underlying drag event with this element as the potential drop target. (Inherited from UIElement)
Drop
Occurs when the input system reports an underlying drop event with this element as the drop target. (Inherited from UIElement)
GotFocus
Occurs when a UIElement receives focus. (Inherited from UIElement)
KeyDown
Occurs when a keyboard key is pressed while the UIElement has focus. (Inherited from UIElement)
KeyUp
Occurs when a keyboard key is released while the UIElement has focus. (Inherited from UIElement)
SizeChanged
Occurs when either the ActualHeight or the ActualWidth property changes value on a FrameworkElement. (Inherited from FrameworkElement)
Focus
Focuses the TextBlock, as if it were a conventionally focusable control.
ToString
Returns the string representation of a Control object. (Inherited from Control.)
Let’s create a new WPF project with the name WPFLabelControl.
Let’s create a new WPF project with the name WPFLabelControl.
Drag one label control from the Toolbox.
Drag one label control from the Toolbox.
Change the different properties of label from the properties window, as shown in the following XAML code.
Change the different properties of label from the properties window, as shown in the following XAML code.
<Window x:Class = "WPFLabelControl.MainWindow" 
   xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
   xmlns:x = "http://schemas.microsoft.com/winfx/2006/xaml" 
   xmlns:d = "http://schemas.microsoft.com/expression/blend/2008" 
   xmlns:mc = "http://schemas.openxmlformats.org/markup-compatibility/2006" 
   xmlns:local = "clr-namespace:WPFLabelControl" 
   mc:Ignorable = "d" Title = "MainWindow" Height = "350" Width = "604">
	
   <Grid> 
      <Label x:Name = "label" Content = "Label Example in WPF" HorizontalAlignment = "Left"
         Margin = "71,82,0,0" VerticalAlignment = "Top" Height = "135" Width = "474" 
         Background = "#FFD6BEBE" FontFamily = "Snap ITC" FontSize = "36"
         FontStyle = "Italic" FontWeight = "Light" Foreground = "#FFBD6B6B"/> 
   </Grid> 
	
</Window>
When you compile and execute the above code, it will produce the following window.