![](/img/trans.png)
[英]ScrollTo not working with grouped ListView in Xamarin.Forms
[英]Searching in grouped ListView in Xamarin.Forms
我按照本指南在Xamarin.Forms
创建了一个分组的ListView
。 这样做,给出以下Property
,该Property
被绑定为ListView
的ItemSource
:
DevicesGrouped = new ObservableCollection<Grouping<string, Device>>(sorted);
一切正常,包括分组功能。
要搜索(从而过滤)列表中的条目,我尝试实现此模式 :
this.ItemsSource = DevicesGrouped
.Where (x => x.Name.ToLower ()
.Contains (filter.ToLower ()));
问题是,由于对象驻留在Groupings
,因此我无法访问Device
的属性。 我只能访问DevicesGrouped
的Key
,在这种情况下,它是一个Manufacturer
,我想搜索Name
。 搜索Key
的问题还在于, ListView
滚动到Key
的位置,从而将ListView
的元素隐藏在分组标题后面。
我的问题是,如何访问ObservableCollection
的Grouped属性?
我已经尝试保留我在过滤时使用的List,但这样做,应用程序崩溃,因为ListView
本身已启用Groupings
。
我在这里先向您的帮助表示感谢。
我找到了我的问题的答案,如果其他人遇到同样的问题,我会发布。
过滤Grouped ListView时,请执行以下操作:
_groupedDeviceList.ItemsSource =
DevicesGrouped.Where(o => o.Any(p => p.Name.ToLower().Contains(filter.ToLower())));
_groupedDeviceList
当然是你自己的列表。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.