簡體   English   中英

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

[英]Searching in grouped ListView in Xamarin.Forms

背景

我按照本指南Xamarin.Forms創建了一個分組的ListView 這樣做,給出以下Property ,該Property被綁定為ListViewItemSource

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

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

要搜索(從而過濾)列表中的條目,我嘗試實現此模式

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

問題

問題是,由於對象駐留在Groupings ,因此我無法訪問Device的屬性。 我只能訪問DevicesGroupedKey ,在這種情況下,它是一個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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM