BindableObject.GetValue(BindableProperty) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
返回 BindableProperty 中包含的值。
public object GetValue (Xamarin.Forms.BindableProperty property);
member this.GetValue : Xamarin.Forms.BindableProperty -> obj
参数
- property
- BindableProperty
要获取该值的 BindableProperty。
返回
BindableProperty 中包含的值。
注解
GetValue(BindableProperty)和 SetValue 用于访问由实现的属性的值 BindableProperty 。 也就是说,应用程序开发人员通常通过定义 public
属性来为绑定属性提供接口,该属性的访问 get
器将 的结果 GetValue(BindableProperty) 强制转换为适当的类型并返回该属性,其 set
访问器使用 SetValue 在正确的属性上设置值。 应用程序开发人员不应在定义绑定属性接口的公共属性中执行其他步骤。
以下示例演示如何为在运行时进行绑定时在目标属性中提供的实现创建可绑定属性接口。
class MyBindable : BindableObject
{
public static readonly BindableProperty MyProperty =
BindableProperty.Create<MyBindable, string> (w => w.My, default(string));
public string My {
get { return (string)GetValue (MyProperty); }
set { SetValue (MyProperty, value); }
}
}