【问题标题】:Searching in grouped ListView in Xamarin.Forms在 Xamarin.Forms 中的分组 ListView 中搜索
【发布时间】:2015-06-02 14:54:32
【问题描述】:

背景

我关注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 的属性,因为对象位于Groupings 中。我只能访问DevicesGrouped 中的Key,在这种情况下,它是Manufacturer,我想在其中搜索Name。搜索Key 的问题还在于,ListView 滚动到Key 的位置,从而将ListView 中的元素隐藏在分组标题后面。

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

我曾尝试保留一个我在过滤时使用的列表,但这样做会导致应用程序崩溃,因为 Groupings 已在 ListView 本身上启用。

提前感谢您的帮助。

【问题讨论】:

    标签: c# listview xamarin observablecollection xamarin.forms


    【解决方案1】:

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

    在过滤您的 Grouped ListView 时简单地执行以下操作:

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

    _groupedDeviceList当然是你自己的名单。

    【讨论】:

    • 我正在尝试做同样的事情,但是当我尝试投射项目 var user = (User)item;
    • 这是有效的,但如果过滤词与任何组匹配,则显示整个组。但我需要确切的内容而不是所有组。
    • 这里也一样。我想做和 Ganeshgm7 一样的事,也想和 Omer Obaid 一样。尽管乍一看它看起来很公平,但它不起作用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多