从Xamarin中的ListView ItemSource访问项目

时间:2017-11-17 15:21:09

标签: xamarin xamarin.forms

我有以下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”的行,如何在不使用文字文字的情况下以编程方式设置绑定,是否有办法?

1 个答案:

答案 0 :(得分:1)

您可以使用nameof(SomeProperty)将属性名称作为字符串