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 的范围。

以下示例演示如何声明具有“内部”写入访问权限的 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); } 
  }
}

适用于