Xamarin.Forms Guides | Samples

Xamarin.Forms.View.HorizontalOptions Property

Gets or sets the LayoutOptions that define how the element gets laid in a layout cycle. This is a bindable property.

Syntax

public LayoutOptions HorizontalOptions { get; set; }

Value

A LayoutOptions which defines how to lay out the element. Default value is LayoutOptions.Fill unless otherwise documented.

Remarks

Assigning the HorizontalOptions modifies how the element is laid out when there is excess space available along the X axis from the parent layout. Additionally it specifies if the element should consume leftover space in the X axis from the parent layout. If multiple children of a layout are set to expand, the extra space is distributed proportionally.

This example creates four views and adds them to a stack, each laying out in a different manner.

C# Example

  private View CreateButtons ()
  {
    var button1 = new Button {Text = "LeftAligned", HorizontalOptions=LayoutOptions.Start};
    var button2 = new Button {Text = "CenterAligned", HorizontalOptions=LayoutOptions.Center};
    var button3 = new Button {Text = "EndAligned", HorizontalOptions=LayoutOptions.End};
    var button4 = new Button {Text = "Fill", HorizontalOptions=LayoutOptions.Fill};

    StackLayout stack = new StackLayout {
      Children = {
        button1,
        button2,
        button3,
        button4
      }
    };

    return stack;
  }

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