【问题标题】:Access items from a ListView ItemSource in Xamarin从 Xamarin 中的 ListView ItemSsource 访问项目
【发布时间】:2017-11-17 23:23:45
【问题描述】:

我有以下 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 };
        });

参考标有“//

【问题讨论】:

    标签: xamarin xamarin.forms


    【解决方案1】:

    您可以使用nameof(SomeProperty) 以字符串形式获取属性名称

    【讨论】:

    • 这并没有真正回答我脑海中的问题,但我没有问得很好。不过,您的答案绝对是一个很好的答案。我想知道是否有任何方法可以访问传递到模板中的项目集合中的独立项目,然后如何访问该单个项目并将其用于绑定。
    • "{Binding .}" 将访问绑定的对象
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-05
    • 1970-01-01
    • 2020-09-08
    • 1970-01-01
    • 1970-01-01
    • 2021-07-03
    • 1970-01-01
    相关资源
    最近更新 更多