BindableObject.SetValue Method

Definition

Overloads

SetValue(BindableProperty, Object)

Sets the value of the specified property.

SetValue(BindablePropertyKey, Object)

Sets the value of the propertyKey.

SetValue(BindableProperty, Object)

Sets the value of the specified property.

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

Parameters

property
BindableProperty

The BindableProperty on which to assign a value.

value
System.Object

The value to set.

Remarks

GetValue(BindableProperty) and SetValue are used to access the values of properties that are implemented by a BindableProperty. That is, application developers typically provide an interface for a bound property by defining public property whose get accessor casts the result of GetValue(BindableProperty) to the appropriate type and returns it, and whose set accessor uses SetValue to set the value on the correct property. Application developers should perform no other steps in the public property that defines the interface of the bound property.

The following example shows how to create a bindable property interface for an implementation that will be provided in the target property when the binding is made at run time.

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

Applies to

SetValue(BindablePropertyKey, Object)

Sets the value of the propertyKey.

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

Parameters

propertyKey
BindablePropertyKey

The BindablePropertyKey on which to assign a value.

value
System.Object

The value to set.

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