BindableObject.SetValue 方法

定義

多載

SetValue(BindableProperty, Object)

設定指定可系結屬性的值。

SetValue(BindablePropertyKey, Object)

設定指定可系結屬性的值。

SetValue(BindableProperty, Object)

設定指定可系結屬性的值。

public:
 void SetValue(Microsoft::Maui::Controls::BindableProperty ^ property, System::Object ^ value);
public void SetValue (Microsoft.Maui.Controls.BindableProperty property, object value);
member this.SetValue : Microsoft.Maui.Controls.BindableProperty * obj -> unit
Public Sub SetValue (property As BindableProperty, value As Object)

參數

property
BindableProperty

要為其指派值的可系結屬性。

value
Object

要設定的值。

例外狀況

propertynull 時擲回。

備註

如果 property 是唯讀的,則不會發生任何動作。

適用於

SetValue(BindablePropertyKey, Object)

設定指定可系結屬性的值。

public:
 void SetValue(Microsoft::Maui::Controls::BindablePropertyKey ^ propertyKey, System::Object ^ value);
public void SetValue (Microsoft.Maui.Controls.BindablePropertyKey propertyKey, object value);
member this.SetValue : Microsoft.Maui.Controls.BindablePropertyKey * obj -> unit
Public Sub SetValue (propertyKey As BindablePropertyKey, value As Object)

參數

propertyKey
BindablePropertyKey

識別要指派值之可系結屬性的索引鍵。

value
Object

要設定的值。

例外狀況

propertyKeynull 時擲回。

當所 propertyKey 識別的可系結屬性是只讀時擲回。

備註

此方法和 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); } 
  }
}

適用於