如何在 Xamarin Forms 中使用 Object Initializer 为 Label 添加 setbinding

How to add setbinding for Label using Object Initializer in Xamarin Forms

有没有办法在 Xamarin Forms 中使用对象初始值设定项在标签内使用 set binding

a) Label lb = new Label();
   lb.setBinding(----);


b) new Label{
**Set Binding** ???
}

,不能使用object initializer设置控件的绑定。

因为(definition from MSDN): 对象初始值设定项允许您在创建时为对象的任何可访问字段或属性赋值,而无需调用构造函数后跟赋值语句行。

您不能使用 SetBinding in Object initilaizer because its not a property or an accessible field, but a method

您必须按如下方式使用 SetBinding:

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