语言

StackLayout 类

定义

在单个垂直或水平行中定位子元素的 Layout<T>。

public class StackLayout : Xamarin.Forms.Layout<Xamarin.Forms.View>, Xamarin.Forms.IElementConfiguration<Xamarin.Forms.StackLayout>
type StackLayout = class
    inherit Layout<View>
    interface IElementConfiguration<StackLayout>
继承
实现

注解

由于 StackLayout 布局会覆盖其子元素上的边界,因此应用程序开发人员不应对其设置边界。

以下示例代码(改编自 FormsGallery 示例)演示如何创建一个子级的新 StackLayout 代码,这些子元素探索了以下许多布局行为 StackLayout:

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.",
                },
            }
        }
    }
};

构造函数

名称 说明
StackLayout()

初始化 StackLayout 类的新实例。

字段

名称 说明
OrientationProperty

标识 Orientation 可绑定属性。

SpacingProperty

标识间距可绑定属性。

属性

名称 说明
AnchorX

获取或设置相对于元素边界的任何转换的中心点的 X 组件。 这是一种可绑定属性。

(继承自 VisualElement)
AnchorY

获取或设置相对于元素边界的任何转换的中心点的 Y 分量。 这是一种可绑定属性。

(继承自 VisualElement)
AutomationId

获取或设置允许自动化框架查找此元素并与其交互的值。

(继承自 Element)
Background

在单个垂直或水平行中定位子元素的 Layout<T>。

(继承自 VisualElement)
BackgroundColor

获取或设置将填充 VisualElement 背景的颜色。 这是一种可绑定属性。

(继承自 VisualElement)
Batched

供Xamarin内部使用。窗体平台。

(继承自 VisualElement)
Behaviors

获取与此元素关联的行为列表。 这是一种可绑定属性。

(继承自 VisualElement)
BindingContext

获取或设置一个对象,该对象包含由属于此 BindableObject属性的绑定属性所面向的属性。

(继承自 BindableObject)
Bounds

获取元素的边界。

(继承自 VisualElement)
CascadeInputTransparent

获取或设置一个值,该值控制子元素在传输时是否继承布局的thistrue输入透明度。

(继承自 Layout)
Children

获取布局子元素的 IList<视图> 。

(继承自 Layout<T>)
class

在单个垂直或水平行中定位子元素的 Layout<T>。

(继承自 NavigableElement)
ClassId

获取或设置用于标识语义相似元素集合的值。

(继承自 Element)
Clip

在单个垂直或水平行中定位子元素的 Layout<T>。

(继承自 VisualElement)
DisableLayout

供Xamarin内部使用。窗体平台。

(继承自 VisualElement)
Dispatcher

在单个垂直或水平行中定位子元素的 Layout<T>。

(继承自 BindableObject)
EffectControlProvider

供Xamarin内部使用。窗体平台。

(继承自 Element)
Effects

应用于此项的效果的列表。

(继承自 Element)
FlowDirection

获取或设置布局流方向。

(继承自 VisualElement)
GestureController

获取视图的手势控制器。

(继承自 View)
GestureRecognizers

与此视图关联的手势识别器的集合。

(继承自 View)
Height

获取此元素的当前呈现高度。 这是一种只读可绑定属性。

(继承自 VisualElement)
HeightRequest

获取或设置此元素所需的高度替代。

(继承自 VisualElement)
HorizontalOptions

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

(继承自 View)
Id

获取一个值,该值可用于通过应用程序运行唯一标识元素。

(继承自 Element)
InputTransparent

获取或设置一个值,该值指示是否应在用户交互周期中涉及此元素。 这是一种可绑定属性。

(继承自 VisualElement)
IsClippedToBounds

获取或设置一个值,该值确定布局是否应将其子级剪辑到其边界。

(继承自 Layout)
IsEnabled

获取或设置一个值,该值指示是否在用户界面中启用此元素。 这是一种可绑定属性。

(继承自 VisualElement)
IsFocused

获取一个值,该值指示当前是否聚焦此元素。 这是一种可绑定属性。

(继承自 VisualElement)
IsInNativeLayout

供Xamarin内部使用。窗体平台。

(继承自 VisualElement)
IsNativeStateConsistent

供Xamarin内部使用。窗体平台。

(继承自 VisualElement)
IsPlatformEnabled

供Xamarin内部使用。窗体平台。

(继承自 VisualElement)
IsTabStop

获取或设置一个值,该值指示此元素是否包含在选项卡导航中。 这是一种可绑定属性。

(继承自 VisualElement)
IsVisible

获取或设置一个值,该值确定此元素是否应是可视化树的一部分。 这是一种可绑定属性。

(继承自 VisualElement)
LogicalChildren

供Xamarin内部使用。窗体平台。

(继承自 Element)
Margin

获取或设置视图的边距。

(继承自 View)
MinimumHeightRequest

获取或设置一个值,该值覆盖元素在布局期间请求的最小高度。

(继承自 VisualElement)
MinimumWidthRequest

获取或设置一个值,该值覆盖元素在布局期间请求的最小宽度。

(继承自 VisualElement)
Navigation

在单个垂直或水平行中定位子元素的 Layout<T>。

(继承自 NavigableElement)
NavigationProxy

在单个垂直或水平行中定位子元素的 Layout<T>。

(继承自 NavigableElement)
Opacity

获取或设置呈现元素时应用于元素的不透明度值。 这是一种可绑定属性。

(继承自 VisualElement)
Orientation

获取或设置指示子元素的定位方向的值。

Padding

获取或设置布局的内部填充。

(继承自 Layout)
Parent

获取或设置元素的父元素。

(继承自 Element)
ParentView
已过时.

获取作为此元素最接近的上级元素的 VisualElement元素。

(继承自 Element)
Platform
已过时.

在单个垂直或水平行中定位子元素的 Layout<T>。

(继承自 Element)
RealParent

供Xamarin内部使用。窗体平台。

(继承自 Element)
Resources

获取或设置本地资源字典。

(继承自 VisualElement)
Rotation

获取或设置呈现元素时围绕 Z 轴(仿射旋转)的旋转角度(以度为单位)。

(继承自 VisualElement)
RotationX

获取或设置呈现元素时围绕 X 轴(透视旋转)的旋转角度(以度为单位)。

(继承自 VisualElement)
RotationY

获取或设置呈现元素时围绕 Y 轴(透视旋转)的旋转角度(以度为单位)。

(继承自 VisualElement)
Scale

获取或设置应用于元素的比例因子。

(继承自 VisualElement)
ScaleX

获取或设置要应用于 X 方向的缩放值。

(继承自 VisualElement)
ScaleY

获取或设置要应用于 Y 方向的缩放值。

(继承自 VisualElement)
Spacing

获取或设置一个值,该值指示每个子元素之间的空间量。

Style

在单个垂直或水平行中定位子元素的 Layout<T>。

(继承自 NavigableElement)
StyleClass

在单个垂直或水平行中定位子元素的 Layout<T>。

(继承自 NavigableElement)
StyleId

获取或设置用于唯一地标识元素的用户定义的值。

(继承自 Element)
TabIndex

在单个垂直或水平行中定位子元素的 Layout<T>。

(继承自 VisualElement)
TranslationX

获取或设置元素的 X 转换增量。

(继承自 VisualElement)
TranslationY

获取或设置元素的 Y 转换增量。

(继承自 VisualElement)
Triggers

获取与此元素关联的触发器列表。 这是一种可绑定属性。

(继承自 VisualElement)
VerticalOptions

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

(继承自 View)
Visual

在单个垂直或水平行中定位子元素的 Layout<T>。

(继承自 VisualElement)
Width

获取此元素的当前呈现宽度。 这是一种只读可绑定属性。

(继承自 VisualElement)
WidthRequest

获取或设置此元素的所需宽度重写。

(继承自 VisualElement)
X

获取此元素的当前 X 位置。 这是一种只读可绑定属性。

(继承自 VisualElement)
Y

获取此元素的当前 Y 位置。 这是一种只读可绑定属性。

(继承自 VisualElement)

方法

名称 说明
ApplyBindings()

将绑定应用到 BindingContext.

(继承自 BindableObject)
BatchBegin()

表示开始对元素属性进行批更改。

(继承自 VisualElement)
BatchCommit()

表示元素命令批处理结束,且现在应提交命令。

(继承自 VisualElement)
ChangeVisualState()

供Xamarin内部使用。窗体平台。

(继承自 VisualElement)
ClearValue(BindableProperty)

清除为 SetValueproperty.. 设置的任何值。

(继承自 BindableObject)
ClearValue(BindablePropertyKey)

清除为 SetValue 由 propertyKey标识的属性设置的任何值。

(继承自 BindableObject)
CoerceValue(BindableProperty)

在单个垂直或水平行中定位子元素的 Layout<T>。

(继承自 BindableObject)
CoerceValue(BindablePropertyKey)

在单个垂直或水平行中定位子元素的 Layout<T>。

(继承自 BindableObject)
Descendants()

供Xamarin内部使用。窗体平台。

(继承自 Element)
EffectIsAttached(String)

供Xamarin内部使用。窗体平台。

(继承自 Element)
FindByName(String)

返回具有指定名称的元素。

(继承自 Element)
Focus()

将焦点设置为此元素的临时。

(继承自 VisualElement)
ForceLayout()

强制元素及其所有子代的布局循环。

(继承自 Layout)
GetChildElements(Point)

返回在指定的 point子元素下方的视觉对象。

(继承自 View)
GetSizeRequest(Double, Double)
已过时.

返回 SizeRequest 布局。 调用此方法将开始布局周期的度量传递。

(继承自 Layout)
GetValue(BindableProperty)

返回 BindableProperty 中包含的值。

(继承自 BindableObject)
GetValues(BindableProperty, BindableProperty, BindableProperty)
已过时.

供Xamarin内部使用。窗体平台。

(继承自 BindableObject)
GetValues(BindableProperty, BindableProperty)
已过时.

供Xamarin内部使用。窗体平台。

(继承自 BindableObject)
InvalidateLayout()

使当前布局无效。

(继承自 Layout)
InvalidateMeasure()

调用的方法使此 VisualElement布局失效。 引发 MeasureInvalidated 事件。

(继承自 VisualElement)
InvalidateMeasureNonVirtual(InvalidationTrigger)

供Xamarin内部使用。窗体平台。

(继承自 VisualElement)
IsSet(BindableProperty)

返回 true 目标属性是否存在且已设置。

(继承自 BindableObject)
Layout(Rectangle)

在布局循环中更新元素的边界。

(继承自 VisualElement)
LayoutChildren(Double, Double, Double, Double)

定位和调整 StackLayout 的子级。

LowerChild(View)

将子级发送到可视堆栈的后面。

(继承自 Layout)
Measure(Double, Double, MeasureFlags)

返回视觉元素在设备上显示所需的最小大小。

(继承自 VisualElement)
NativeSizeChanged()

供Xamarin内部使用。窗体平台。

(继承自 VisualElement)
On<T>()

返回开发人员可用于为布局调用特定于平台的方法的配置对象。

OnAdded(T)

向布局添加子级时调用。 实现此方法可为此事件添加类处理。

(继承自 Layout<T>)
OnBindingContextChanged()

每当 View 的绑定上下文发生更改时就会调用。 重写此方法可为此事件添加类处理。

(继承自 View)
OnChildAdded(Element)

应用程序开发人员可以重写此方法,以在添加子级时做出响应。

(继承自 Layout<T>)
OnChildMeasureInvalidated()

每当布局的子级发出 MeasureInvalidated 时调用。 实现此方法可为此事件添加类处理。

(继承自 Layout)
OnChildMeasureInvalidated(Object, EventArgs)

每当布局的子级发出 MeasureInvalidated 时调用。 实现此方法可为此事件添加类处理。

(继承自 Layout)
OnChildRemoved(Element, Int32)

在单个垂直或水平行中定位子元素的 Layout<T>。

(继承自 Layout<T>)
OnChildRemoved(Element)
已过时.

应用程序开发人员可以重写此方法,以在删除子级时做出响应。

(继承自 Layout<T>)
OnChildrenReordered()

每当 ChildrenReordered 即将发出事件时调用。 实现此方法可为此事件添加类处理。

(继承自 VisualElement)
OnMeasure(Double, Double)

进行布局测量时调用的方法。

(继承自 VisualElement)
OnParentSet()

在单个垂直或水平行中定位子元素的 Layout<T>。

(继承自 NavigableElement)
OnPropertyChanged(String)

更改绑定属性时调用的方法。

(继承自 Element)
OnPropertyChanging(String)

从子类调用此方法,以通知属性上将发生更改。

(继承自 BindableObject)
OnRemoved(T)

从布局中删除子级时调用。 实现此方法可为此事件添加类处理。

(继承自 Layout<T>)
OnSizeAllocated(Double, Double)

当在布局周期中设置元素的大小时,将调用此方法。 在发出事件之前 SizeChanged ,直接调用此方法。 实现此方法可为此事件添加类处理。

(继承自 Layout)
OnSizeRequest(Double, Double)
已过时.

此方法是在布局周期的度量传递期间调用的,以获取 StackLayout 的所需大小。

OnTabIndexPropertyChanged(Int32, Int32)

在单个垂直或水平行中定位子元素的 Layout<T>。

(继承自 VisualElement)
OnTabStopPropertyChanged(Boolean, Boolean)

在单个垂直或水平行中定位子元素的 Layout<T>。

(继承自 VisualElement)
RaiseChild(View)

将子级发送到可视堆栈的前面。

(继承自 Layout)
RemoveBinding(BindableProperty)

删除以前设置的绑定。

(继承自 BindableObject)
RemoveDynamicResource(BindableProperty)

删除以前设置的动态资源

(继承自 Element)
ResolveLayoutChanges()

在单个垂直或水平行中定位子元素的 Layout<T>。

(继承自 Layout)
SetBinding(BindableProperty, BindingBase)

向属性分配绑定。

(继承自 BindableObject)
SetDynamicResource(BindableProperty, String)

使用提供的键设置要通过 DynamicResource 更新此元素的 BindableProperty 属性。

(继承自 Element)
SetValue(BindableProperty, Object)

设置指定属性的值。

(继承自 BindableObject)
SetValue(BindablePropertyKey, Object)

设置 propertyKey 的值。

(继承自 BindableObject)
SetValueCore(BindableProperty, Object, SetValueFlags)

供Xamarin内部使用。窗体平台。

(继承自 BindableObject)
SetValueFromRenderer(BindableProperty, Object)

供Xamarin内部使用。窗体平台。

(继承自 Element)
SetValueFromRenderer(BindablePropertyKey, Object)

供Xamarin内部使用。窗体平台。

(继承自 Element)
ShouldInvalidateOnChildAdded(View)

实现时,应返回 true 应 child 调用 InvalidateMeasure(),如果不应返回,则返回 false 。

(继承自 Layout)
ShouldInvalidateOnChildRemoved(View)

实现时,应返回 true 在 child 删除时应调用 InvalidateMeasure() ,如果不应返回,则返回 false 。

(继承自 Layout)
SizeAllocated(Double, Double)

在布局周期期间调用 SizeAllocated,以指示子树布局的开始。

(继承自 VisualElement)
TabIndexDefaultValueCreator()

在单个垂直或水平行中定位子元素的 Layout<T>。

(继承自 VisualElement)
TabStopDefaultValueCreator()

在单个垂直或水平行中定位子元素的 Layout<T>。

(继承自 VisualElement)
UnapplyBindings()

取消应用以前设置的所有绑定。

(继承自 BindableObject)
Unfocus()

取消设置此元素的焦点。

(继承自 VisualElement)
UpdateChildrenLayout()

指示布局以对其所有子级进行重新布局。

(继承自 Layout)

活动

名称 说明
BatchCommitted

供Xamarin内部使用。窗体平台。

(继承自 VisualElement)
BindingContextChanged

每当 BindingContext 属性更改时引发。

(继承自 BindableObject)
ChildAdded

每当将子元素添加到元素时发生。

(继承自 Element)
ChildRemoved

每当从元素中删除子元素时发生。

(继承自 Element)
ChildrenReordered

重新排序 VisualElement 的子级时发生。

(继承自 VisualElement)
DescendantAdded

每当将子元素添加到元素子树时发生。

(继承自 Element)
DescendantRemoved

每当从元素子树中删除子元素时发生。

(继承自 Element)
FocusChangeRequested

供Xamarin内部使用。窗体平台。

(继承自 VisualElement)
Focused

当元素接收焦点时发生。

(继承自 VisualElement)
LayoutChanged

如果任何子元素的 Bounds 已更改,则在布局循环结束时发生。

(继承自 Layout)
MeasureInvalidated

当视觉元素的布局失效时引发的事件。

(继承自 VisualElement)
PlatformSet
已过时.

在单个垂直或水平行中定位子元素的 Layout<T>。

(继承自 Element)
PropertyChanged

属性发生更改时引发。

(继承自 BindableObject)
PropertyChanging

当属性即将更改时引发。

(继承自 BindableObject)
SizeChanged

当 Width 或 Height 属性更改此元素上的值时发生。

(继承自 VisualElement)
Unfocused

当元素失去焦点时发生。

(继承自 VisualElement)

显式接口实现

名称 说明
IDynamicResourceHandler.SetDynamicResource(BindableProperty, String)

供Xamarin内部使用。窗体平台。

(继承自 BindableObject)
IElementController.SetValueFromRenderer(BindableProperty, Object)

供Xamarin内部使用。窗体平台。

(继承自 Element)
IGestureController.CompositeGestureRecognizers

供Xamarin内部使用。窗体平台。

(继承自 View)
INameScope.RegisterName(String, Object)

仅供内部使用。

(继承自 Element)
IVisualElementController.EffectiveFlowDirection

获取平台上元素的有效视觉流方向,同时考虑区域设置和逻辑流设置。

(继承自 VisualElement)
IVisualElementController.InvalidateMeasure(InvalidationTrigger)

此方法供内部使用。

(继承自 VisualElement)

扩展方法

名称 说明
AbortAnimation(IAnimatable, String)

停止动画。

Animate(IAnimatable, String, Action<Double>, Double, Double, UInt32, UInt32, Easing, Action<Double,Boolean>, Func<Boolean>)

设置指定的参数并启动动画。

Animate(IAnimatable, String, Action<Double>, UInt32, UInt32, Easing, Action<Double,Boolean>, Func<Boolean>)

设置指定的参数并启动动画。

Animate(IAnimatable, String, Animation, UInt32, UInt32, Easing, Action<Double,Boolean>, Func<Boolean>)

设置指定的参数并启动动画。

Animate<T>(IAnimatable, String, Func<Double,T>, Action<T>, UInt32, UInt32, Easing, Action<T,Boolean>, Func<Boolean>)

设置指定的参数并启动动画。

AnimateKinetic(IAnimatable, String, Func<Double,Double,Boolean>, Double, Double, Action)

设置指定参数并启动动态动画。

AnimationIsRunning(IAnimatable, String)

返回一个布尔值,该值指示 handle 指定的动画是否正在运行。

Batch(IAnimatable)

在单个垂直或水平行中定位子元素的 Layout<T>。

FadeTo(VisualElement, Double, UInt32, Easing)

返回一个任务,它执行 opacity、length 和 easing 参数描述的淡化。

FindByName<T>(Element, String)

返回范围中包含element名称name的类型T实例。

FindNextElement(ITabStopElement, Boolean, IDictionary<Int32,List<ITabStopElement>>, Int32)

在单个垂直或水平行中定位子元素的 Layout<T>。

GetPropertyIfSet<T>(BindableObject, BindableProperty, T)

在单个垂直或水平行中定位子元素的 Layout<T>。

GetSortedTabIndexesOnParentPage(VisualElement)

在单个垂直或水平行中定位子元素的 Layout<T>。

GetTabIndexesOnParentPage(ITabStopElement, Int32)

在单个垂直或水平行中定位子元素的 Layout<T>。

HasVisualStateGroups(VisualElement)

返回 true 是否 element 具有一个或多个与之关联的视觉状态组。 否则,返回 false。

LayoutTo(VisualElement, Rectangle, UInt32, Easing)

返回一个任务,该任务可简化由view参数指定的矩形所指定的bounds边界VisualElement。

RelRotateTo(VisualElement, Double, UInt32, Easing)

从当前旋转将 VisualElement 指定的 view 旋转为 drotation。

RelScaleTo(VisualElement, Double, UInt32, Easing)

返回一个任务,它将 VisualElement 指定的 view 从其当前比例缩放到 dscale。

RotateTo(VisualElement, Double, UInt32, Easing)

返回执行由参数lengtheasing和参数描述的rotation旋转的任务。

RotateXTo(VisualElement, Double, UInt32, Easing)

返回一个任务,该任务通过opacity花费时间和使用easing来length倾斜 Y 轴。

RotateYTo(VisualElement, Double, UInt32, Easing)

返回一个任务,该任务通过opacity花费时间和使用easing时间length来倾斜 X 轴。

ScaleTo(VisualElement, Double, UInt32, Easing)

返回一个任务,它将 VisualElement 指定的 view 缩放到绝对比例因子 scale。

ScaleXTo(VisualElement, Double, UInt32, Easing)

在单个垂直或水平行中定位子元素的 Layout<T>。

ScaleYTo(VisualElement, Double, UInt32, Easing)

在单个垂直或水平行中定位子元素的 Layout<T>。

SetAppThemeColor(BindableObject, BindableProperty, Color, Color)

在单个垂直或水平行中定位子元素的 Layout<T>。

SetBinding(BindableObject, BindableProperty, String, BindingMode, IValueConverter, String)

创建绑定并将其应用到属性。

SetBinding<TSource>(BindableObject, BindableProperty, Expression<Func<TSource,Object>>, BindingMode, IValueConverter, String)
已过时.

从表达式创建并应用绑定。

SetOnAppTheme<T>(BindableObject, BindableProperty, T, T)

在单个垂直或水平行中定位子元素的 Layout<T>。

TranslateTo(VisualElement, Double, Double, UInt32, Easing)

将元素 TranslationX 和 TranslationY 属性从其当前值动画到新值。 这可确保输入布局与视觉对象布局处于同一位置。

适用于