Element 类

定义

为所有 Xamarin.Forms 分层元素提供基类。 此类包含表示 Xamarin.Forms 层次结构中的元素所需的所有方法和属性。

public abstract class Element : Xamarin.Forms.BindableObject, Xamarin.Forms.IElementController, Xamarin.Forms.Internals.INameScope
type Element = class
    inherit BindableObject
    interface INameScope
    interface IElementController
继承
派生
实现

注解

下表中记录了视觉元素的重要类别:

描述
VisualElement 占据屏幕某个区域的 Element 具有可视化外观,并可获得触摸输入。
Cell 单元是要添加到 ListViewTableView 的元素。
Page 一个 VisualElement ,它占据屏幕的大部分或全部,并且包含一个子级。
Layout Layout具有一个类型的子类型 View ,而的子类 Layout<T> 具有多个子视图的集合,其中包括其他布局。
控件和专用 Views关系图的下半部分显示了适用于通用控件(如 Buttons 和 TableViews)的 Xamarin.Forms 类。

构造函数

Element()

用于初始化元素的受保护的构造函数。

字段

AutomationIdProperty

AutomationId 字段的后备存储。

ClassIdProperty

标识 ClassId 可绑定属性。

MenuProperty

附加菜单属性的后备存储。

属性

AutomationId

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

BindingContext

获取或设置对象,该对象包含将被属于此 BindableObject 的绑定属性设定为目标的属性。

(继承自 BindableObject)
ClassId

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

Dispatcher

为所有 Xamarin.Forms 分层元素提供基类。 此类包含表示 Xamarin.Forms 层次结构中的元素所需的所有方法和属性。

(继承自 BindableObject)
EffectControlProvider

供 Xamarin.Forms 平台内部使用。

Effects

应用于此项的效果列表。

Id

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

LogicalChildren

供 Xamarin.Forms 平台内部使用。

Parent

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

ParentView
已过时。

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

Platform
已过时。

为所有 Xamarin.Forms 分层元素提供基类。 此类包含表示 Xamarin.Forms 层次结构中的元素所需的所有方法和属性。

RealParent

供 Xamarin.Forms 平台内部使用。

StyleId

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

方法

ApplyBindings()

将绑定应用到 BindingContext

(继承自 BindableObject)
ClearValue(BindableProperty)

清除由 SetValueproperty 设置的任何值。

(继承自 BindableObject)
ClearValue(BindablePropertyKey)

清除由 SetValuepropertyKey 标识的属性设置的任何值。

(继承自 BindableObject)
CoerceValue(BindableProperty)

为所有 Xamarin.Forms 分层元素提供基类。 此类包含表示 Xamarin.Forms 层次结构中的元素所需的所有方法和属性。

(继承自 BindableObject)
CoerceValue(BindablePropertyKey)

为所有 Xamarin.Forms 分层元素提供基类。 此类包含表示 Xamarin.Forms 层次结构中的元素所需的所有方法和属性。

(继承自 BindableObject)
Descendants()

供 Xamarin.Forms 平台内部使用。

EffectIsAttached(String)

供 Xamarin.Forms 平台内部使用。

FindByName(String)

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

GetMenu(BindableObject)

获取 bindableMenu 对象。

GetValue(BindableProperty)

返回 BindableProperty 中包含的值。

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

供 Xamarin.Forms 平台内部使用。

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

供 Xamarin.Forms 平台内部使用。

(继承自 BindableObject)
IsSet(BindableProperty)

如果目标属性存在并且已设置,则返回 true

(继承自 BindableObject)
OnBindingContextChanged()

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

OnChildAdded(Element)

每当需要发出 ChildAdded 事件时就会调用。 实现此方法可为此事件添加类处理。

OnChildRemoved(Element)
已过时。

每当需要发出 ChildRemoved 事件时就会调用。 实现此方法可为此事件添加类处理。

OnChildRemoved(Element, Int32)

为所有 Xamarin.Forms 分层元素提供基类。 此类包含表示 Xamarin.Forms 层次结构中的元素所需的所有方法和属性。

OnParentSet()

每当设置元素的父级时就会调用。 实现此方法以便在将元素添加到父元素时添加行为。

OnPropertyChanged(String)

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

OnPropertyChanging(String)

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

(继承自 BindableObject)
RemoveBinding(BindableProperty)

删除先前设置的绑定。

(继承自 BindableObject)
RemoveDynamicResource(BindableProperty)

移除先前设置的动态资源

SetBinding(BindableProperty, BindingBase)

向属性分配绑定。

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

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

SetMenu(BindableObject, Menu)

设置 bindable 的菜单。

SetValue(BindableProperty, Object)

设置指定属性的值。

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

设置 propertyKey 的值。

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

供 Xamarin.Forms 平台内部使用。

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

供 Xamarin.Forms 平台内部使用。

SetValueFromRenderer(BindablePropertyKey, Object)

供 Xamarin.Forms 平台内部使用。

UnapplyBindings()

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

(继承自 BindableObject)

事件

BindingContextChanged

只要 BindingContext 属性更改就会引发。

(继承自 BindableObject)
ChildAdded

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

ChildRemoved

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

DescendantAdded

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

DescendantRemoved

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

PlatformSet
已过时。

为所有 Xamarin.Forms 分层元素提供基类。 此类包含表示 Xamarin.Forms 层次结构中的元素所需的所有方法和属性。

PropertyChanged

在属性已更改时引发。

(继承自 BindableObject)
PropertyChanging

在属性将要更改时引发。

(继承自 BindableObject)

显式接口实现

IDynamicResourceHandler.SetDynamicResource(BindableProperty, String)

供 Xamarin.Forms 平台内部使用。

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

供 Xamarin.Forms 平台内部使用。

INameScope.RegisterName(String, Object)

仅限内部使用。

扩展方法

GetPropertyIfSet<T>(BindableObject, BindableProperty, T)

为所有 Xamarin.Forms 分层元素提供基类。 此类包含表示 Xamarin.Forms 层次结构中的元素所需的所有方法和属性。

SetAppThemeColor(BindableObject, BindableProperty, Color, Color)

为所有 Xamarin.Forms 分层元素提供基类。 此类包含表示 Xamarin.Forms 层次结构中的元素所需的所有方法和属性。

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

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

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

通过表达式创建并应用绑定。

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

为所有 Xamarin.Forms 分层元素提供基类。 此类包含表示 Xamarin.Forms 层次结构中的元素所需的所有方法和属性。

FindByName<T>(Element, String)

返回包含 element 的作用域中名称为 name 的类型 T 的实例。

适用于