【发布时间】:2015-06-02 14:54:32
【问题描述】:
背景
我关注this guide 在Xamarin.Forms 中创建了一个分组ListView。这样做会给出以下Property,它被绑定为ListView 的ItemSource:
DevicesGrouped = new ObservableCollection<Grouping<string, Device>>(sorted);
一切正常,包括分组功能。
为了搜索(从而过滤)列表中的条目,我尝试实现this pattern:
this.ItemsSource = DevicesGrouped
.Where (x => x.Name.ToLower ()
.Contains (filter.ToLower ()));
问题
问题是,我无法访问Device 的属性,因为对象位于Groupings 中。我只能访问DevicesGrouped 中的Key,在这种情况下,它是Manufacturer,我想在其中搜索Name。搜索Key 的问题还在于,ListView 滚动到Key 的位置,从而将ListView 中的元素隐藏在分组标题后面。
因此,我的问题是,如何访问分组的ObservableCollection 的属性?
我曾尝试保留一个我在过滤时使用的列表,但这样做会导致应用程序崩溃,因为 Groupings 已在 ListView 本身上启用。
提前感谢您的帮助。
【问题讨论】:
标签: c# listview xamarin observablecollection xamarin.forms