View.VerticalOptions 属性

定义

获取或设置 LayoutOptions,它定义元素在布局周期中的布局方式。 这是一种可绑定属性。

public Xamarin.Forms.LayoutOptions VerticalOptions { get; set; }
member this.VerticalOptions : Xamarin.Forms.LayoutOptions with get, set

属性值

一个 LayoutOptions ,它定义如何布局元素。 除非另有说明,否则默认值为 Fill

注解

分配 VerticalOptions 可修改在父布局的 Y 轴上存在多余的空间时元素的布局方式。 此外,它还指定元素是否应消耗父版式中 Y 轴中的剩余空间。 如果一个布局的多个子级设置为展开,则额外空间按比例分布。

此示例创建四个视图并将其添加到堆栈中,每个视图都以不同的方式进行布局。

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

  StackLayout stack = new StackLayout {
    Orientation = StackOrientation.Horizontal,
    Children = {
      button1,
      button2,
      button3,
      button4
    }
  };

  return stack;
}

适用于