BindableObject.SetValue Method

Definition

Overloads

SetValue(BindableProperty, Object)

Sets the value of the specified bindable property.

SetValue(BindablePropertyKey, Object)

Sets the value of the specified bindable property.

SetValue(BindableProperty, Object)

Sets the value of the specified bindable property.

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)

Parameters

property
BindableProperty

The bindable property on which to assign a value.

value
Object

The value to set.

Exceptions

Thrown when property is null.

Remarks

If property is read-only, nothing will happen.

Applies to

SetValue(BindablePropertyKey, Object)

Sets the value of the specified bindable property.

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)

Parameters

propertyKey
BindablePropertyKey

The key that identifies the bindable property to assign the value to.

value
Object

The value to set.

Exceptions

Thrown when propertyKey is null.

Thrown when the bindable property identified by propertyKey is read-only.

Remarks

This method and BindablePropertyKey are useful to implement BindableProperties with limited write access. The write access is limited to the scope of the BindablePropertyKey.

The following example shows how to declare a BindableProperty with "internal" write access.

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); } 
  }
}

Applies to