BindableObject.SetValue 方法

定義

多載

SetValue(BindableProperty, Object)

設定指定之屬性的值。

SetValue(BindablePropertyKey, Object)

設定 propertyKey 的值。

SetValue(BindableProperty, Object)

設定指定之屬性的值。

public void SetValue (Xamarin.Forms.BindableProperty property, object value);
member this.SetValue : Xamarin.Forms.BindableProperty * obj -> unit

參數

property
BindableProperty

要在其上指派值的 BindableProperty。

value
Object

要設定的值。

備註

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

適用於

SetValue(BindablePropertyKey, Object)

設定 propertyKey 的值。

public void SetValue (Xamarin.Forms.BindablePropertyKey propertyKey, object value);
member this.SetValue : Xamarin.Forms.BindablePropertyKey * obj -> unit

參數

propertyKey
BindablePropertyKey

要在其上指派值的 BindablePropertyKey。

value
Object

要設定的值。

備註

此方法和 BindablePropertyKey 對於實作 BindableProperties 具有有限寫入存取權很有用。 寫入權限僅限於 BindablePropertyKey 的範圍。

下列範例示範如何使用 「internal」 寫入權限來宣告 BindableProperty。

class MyBindable : BindableObject
{
  internal static readonly BindablePropertyKey MyPropertyKey = 
    BindableProperty.CreateReadOnly<MyBindable, string> (w => w.My, default(string));
  public static readonly BindableProperty MyProperty = MyPropertyKey.BindableProperty;

  public string My {
    get { return (string)GetValue (MyProperty); }
    internal set { SetValue (MyPropertyKey, value); } 
  }
}

適用於