Xamarin.Forms.Label Class
A Xamarin.Forms.View that displays text.

See Also: Label Members

Syntax

[Xamarin.Forms.ContentProperty("Text")]
public class Label : View, IFontElement

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
    {
        public static Page GetMainPage ()
        {    
            return new ContentPage { 
                Content = new Label {
                    Text = "Hello, Forms!",
                    Font = Font.SystemFontOfSize(NamedSize.Large),
                    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.

The Xamarin.Forms.Label class has the following XAML properties:

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 Xamarin.Forms.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.

XAlign

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

YAlign

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