在 Xamarin.Forms 中的分组 ListView 中搜索

Searching in grouped ListView in Xamarin.Forms

背景

我按照 this guideXamarin.Forms 中创建了一个分组 ListView。这样做,下面的 Property 被绑定为 ListViewItemSource:

DevicesGrouped = new ObservableCollection<Grouping<string, Device>>(sorted);

一切正常,包括分组功能。

为了搜索(从而过滤)列表中的条目,我尝试实现 this pattern:

this.ItemsSource = DevicesGrouped
        .Where (x => x.Name.ToLower ()
        .Contains (filter.ToLower ()));

问题

问题是,我无法访问 Device 的属性,因为 objects 驻留在 Groupings 中。我只能访问 DevicesGroupedKey,在本例中,它是 Manufacturer,我想在其中搜索 Name。搜索 Key 的问题还在于,ListView 滚动到 Key 的位置,从而将 ListView 中的元素隐藏在分组 [=57 后面=].

因此我的问题是,如何访问已分组的 ObservableCollection 的属性?

我尝试保留一个我在过滤时使用的列表,但是这样做,应用程序崩溃了,因为 ListView 本身启用了 Groupings

提前感谢您的帮助。

我找到了我的问题的答案,如果其他人 运行 遇到同样的问题,我会 post 它。

过滤 Grouped ListView 时只需执行以下操作:

_groupedDeviceList.ItemsSource =
                DevicesGrouped.Where(o => o.Any(p => p.Name.ToLower().Contains(filter.ToLower())));

_groupedDeviceList当然是你自己的列表。