BindableObject.SetBinding(BindableProperty, BindingBase) 方法

定义

向属性分配绑定。

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

参数

targetProperty
BindableProperty

要在其上设置绑定的 BindableProperty。

binding
BindingBase

要设置的绑定。

注解

以下示例演示如何将绑定设置为 属性:

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"

适用于