Xamarin.Forms Guides | Samples

Xamarin.Forms.Label Class

A View that displays text.

See Also: Label

Syntax

[Xamarin.Forms.ContentProperty("Text")]
[Xamarin.Forms.RenderWith(typeof(Xamarin.Forms.Platform._LabelRenderer))]
public class Label : View, IElementConfiguration<Label>

Remarks

A Label is used to display single-line text elements as well as multi-line blocks of text.

The following example, adapted from the default Xamarin Forms solution, shows a basic use:

C# Example

public class App : Application
{
    public App ()
    {
    MainPage = new ContentPage { 
        Content = new Label {
            Text = "Hello, Forms!",
            FontSize = Device.GetNamedSize (NamedSize.Large, typeof(Label)),
            VerticalOptions = LayoutOptions.CenterAndExpand,
            HorizontalOptions = LayoutOptions.CenterAndExpand,
        },
    };
}

The FormsGallery sample, which can be found on the Sample Applications page, has a LabelDemoPage.cs file. This file contains a longer and more complete example.

XAML for Xamarin.Forms supports the following properties for the Label class:

PropertyValue
Font

Deprecated. Use FontAttributes, FontFamily, and FontSize, instead. A string of the format [name],[attributes],[size]. The font specification may contain multiple attributes, e.g. Georgia, Bold, Italic, 42.

FontAttributes

Bold, Bold,Italic, or None.

FontFamily

A font family, such as sans-serif or monospace.

FontSize

A named size, such as Large, or an integer that represents the size in device units.

LineBreakMode

A string that corresponds to a LineBreakMode enumeration value.

Text

The text that will appear on the label.

TextColor

A color specification, with or without the prefix, "Color". For example, "Color.Red" and "Red" both specify the color red.

HorizontalTextAlignment

Center, End, or Start, to indicate the horizontal placement of the label text.

VerticalTextAlignment

Center, End, or Start, to indicate the vertical placement of the label text.

Requirements

Namespace: Xamarin.Forms
Assembly: Xamarin.Forms.Core (in Xamarin.Forms.Core.dll)
Assembly Versions: 1.0.0.0, 1.1.0.0, 1.2.0.0, 1.3.0.0, 1.4.0.0, 1.5.0.0, 2.0.0.0

The members of Xamarin.Forms.Label are listed below.

See Also: View

Public Constructors

Initializes a new instance of the Label class.

Public Fields

static readonly
FontAttributesPropertyBindableProperty. Backing store for the FontAttributes property.
static readonly
FontFamilyPropertyBindableProperty. Backing store for the FontFamily property.
static readonly
FontPropertyBindableProperty. Backing store for the Font bindable property.
static readonly
FontSizePropertyBindableProperty. Backing store for the FontSize property.
static readonly
FormattedTextPropertyBindableProperty. Backing store for the FormattedText property.
static readonly
HorizontalTextAlignmentPropertyBindableProperty. Identifies the HorizontalTextAlignment bindable property
static readonly
LineBreakModePropertyBindableProperty. Backing store for the LineBreakMode bindable property.
static readonly
TextColorPropertyBindableProperty. Backing store for the TextColor bindable property.
static readonly
TextPropertyBindableProperty. Backing store for the Text bindable property.
static readonly
VerticalTextAlignmentPropertyBindableProperty. Identifies the VerticalTextAlignment bindable property.
static readonly
XAlignPropertyBindableProperty. Backing store for the XAlign bindable property.
static readonly
YAlignPropertyBindableProperty. Backing store for the YAlign bindable property.

Public Properties

FontFont. Gets or sets the Font for the Label. This is a bindable property.
FontAttributesFontAttributes. Gets a value that indicates whether the font for the label is bold, italic, or neither.
FontFamilyString. Gets the font family to which the font for the label belongs.
FontSizeDouble. Gets the size of the font for the label.
FormattedTextFormattedString. Gets or sets the formatted text for the Label. This is a bindable property.
HorizontalTextAlignmentTextAlignment. Gets or sets the horizontal alignement of the Text property. This is a bindable property.
LineBreakModeLineBreakMode. Gets or sets the LineBreakMode for the Label. This is a bindable property.
TextString. Gets or sets the text for the Label. This is a bindable property.
TextColorColor. Gets or sets the Color for the text of this Label. This is a bindable property.
VerticalTextAlignmentTextAlignment. Gets or sets the vertical alignement of the Text property. This is a bindable property.
XAlignTextAlignment. Gets or sets the horizontal alignment for the Text inside of the Label bound.
YAlignTextAlignment. Gets or sets the vertical alignment for the Text inside of the Label bound.

Public Methods

On<T>() : IPlatformElementConfiguration<T, Label>
Returns the platform-specific instance of this Label, on which a platform-specific method may be called.