BindableObject.GetValue(BindableProperty) 方法

定義

傳回 BindableProperty 中包含的值。

public object GetValue (Xamarin.Forms.BindableProperty property);
member this.GetValue : Xamarin.Forms.BindableProperty -> obj

參數

property
BindableProperty

要為其取得值的 BindableProperty。

傳回

BindableProperty 中包含的值。

備註

GetValue(BindableProperty)SetValue 是用來存取由所執行的屬性值 BindableProperty 。 也就是說,應用程式開發人員通常會藉由定義 publicget 存取子將 結果轉換成適當型別並傳回其結果 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); } 
  }
}

適用於