Xamarin.Forms.StackLayout Class
See Also: StackLayout
Syntax
Remarks
Because StackLayout layouts override the bounds on their child elements, application developers should not set bounds on them.
The following example code, adapted from the FormsGallery example shows how to create a new StackLayout with children that explore many of the layout behaviors of StackLayout:
C# Example
StackLayout stackLayout = new StackLayout
{
Spacing = 0,
VerticalOptions = LayoutOptions.FillAndExpand,
Children =
{
new Label
{
Text = "StackLayout",
HorizontalOptions = LayoutOptions.Start
},
new Label
{
Text = "stacks its children",
HorizontalOptions = LayoutOptions.Center
},
new Label
{
Text = "vertically",
HorizontalOptions = LayoutOptions.End
},
new Label
{
Text = "by default,",
HorizontalOptions = LayoutOptions.Center
},
new Label
{
Text = "but horizontal placement",
HorizontalOptions = LayoutOptions.Start
},
new Label
{
Text = "can be controlled with",
HorizontalOptions = LayoutOptions.Center
},
new Label
{
Text = "the HorizontalOptions property.",
HorizontalOptions = LayoutOptions.End
},
new Label
{
Text = "An Expand option allows one or more children " +
"to occupy the an area within the remaining " +
"space of the StackLayout after it's been sized " +
"to the height of its parent.",
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.End
},
new StackLayout
{
Spacing = 0,
Orientation = StackOrientation.Horizontal,
Children =
{
new Label
{
Text = "Stacking",
},
new Label
{
Text = "can also be",
HorizontalOptions = LayoutOptions.CenterAndExpand
},
new Label
{
Text = "horizontal.",
},
}
}
}
};
XAML for Xamarin.Forms supports the following properties for the StackLayout class:
| Property | Value |
|---|---|
| Orientation | Horizontal or Vertical. The default is Vertical. |
| Spacing | An integer or decimal. |
Requirements
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.3.3.0, 1.4.0.0, 1.5.0.0, 2.0.0.0
The members of Xamarin.Forms.StackLayout are listed below.
See Also: Inherited members from Xamarin.Forms.Layout<Xamarin.Forms.View>
Public Constructors
| Initializes a new instance of the StackLayout class. |
Public Fields
static readonly | OrientationProperty | BindableProperty. Identifies the Orientation bindable property. |
static readonly | SpacingProperty | BindableProperty. Identifies the Spacing bindable property. |
Public Properties
| Orientation | StackOrientation. Gets or sets the value which indicates the direction which child elements are positioned. | |
| Spacing | Double. Gets or sets a value which indicates the amount of space between each child element. |
Protected Methods
override | InvalidateMeasure()Invalidates the layout. | |
override | LayoutChildren(Double, Double, Double, Double)Positions and sizes the children of a StackLayout. | |
override | OnSizeRequest(Double, Double)This method is called during the measure pass of a layout cycle to get the desired size of the StackLayout. | |