我有以下ListView和相关模板:
listView = new ListView()
{
ItemTemplate = dtemplate
};
listView.SetBinding(ListView.ItemsSourceProperty, new Binding("Items"));
var dtemplate = new DataTemplate(() =>
{
var stacklayout = new StackLayout()
{
Orientation = StackOrientation.Horizontal
};
var lbl = new Label();
lbl.SetBinding(Label.TextProperty, new Binding("Title")); //<-- this
stacklayout.Children.Add(lbl);
return new ViewCell { View = stacklayout };
});
参考标有“//&lt; - this”的行,如何在不使用文字文字的情况下以编程方式设置绑定,是否有办法?
答案 0 :(得分:1)
您可以使用nameof(SomeProperty)
将属性名称作为字符串