Share via


BindableObject.SetBinding(BindableProperty, BindingBase) Method

Definition

Assigns a binding to a property.

public void SetBinding (Xamarin.Forms.BindableProperty targetProperty, Xamarin.Forms.BindingBase binding);
member this.SetBinding : Xamarin.Forms.BindableProperty * Xamarin.Forms.BindingBase -> unit

Parameters

targetProperty
BindableProperty

The BindableProperty on which to set a binding.

binding
BindingBase

The binding to set.

Remarks

The following example shows how to set a binding to a property:

var label = new Label ();
label.SetBinding (Label.TextProperty, new Binding ("Name"));
label.BindingContext = new {
    Name = "John Doe",
    Company = "Xamarin"
};

Debug.WriteLine (label.Text); // prints "John Doe"

Applies to