BindableObject.SetValue 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
多載
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
要設定的值。
例外狀況
當 property
為 null
時擲回。
備註
如果 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
要設定的值。
例外狀況
當 propertyKey
為 null
時擲回。
當所 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); }
}
}
適用於
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應