需要帮助过滤AlphaKEyGroup

时间:2015-12-04 16:29:47

标签: c# listview windows-phone-8.1 longlistselector

我一直在搜索网站和互联网,试图找到解决方案,但我找不到它。

我使用Microsoft提供的AlphaKeyGroup示例订购了我的商品。但是,用户将在顶部有一个搜索框来过滤此列表,我无法了解如何进行此过滤。

MS说

private void getListItems()
    {
        var alphaKeyGroup = AlphaKeyGroup<Stores>.CreateGroups(
Database_Controller.getStoreValues(), // basic list of items
(Stores s) => { return s.Name; },  // the property to sort
 true);                           // order the items
        // returns type List<AlphaKeyGroup<SampleItem>>

        ListViewCollectionSource.Source = alphaKeyGroup;
    }

所以我尝试了这两种方式

var alphaKeyGroup = AlphaKeyGroup<Stores>.CreateGroups(Database_Controller.getStoreValues(), (Stores s) => s.Name, true).Where(s => Name.Contains(searchKeyword.Text));


var alphaKeyGroup = AlphaKeyGroup<Stores>.CreateGroups(Database_Controller.getStoreValues(), (Stores s) => { return s.Name.Where(s.Name.Contains(searchKeyword.Text)) ; },true);

第一个没有给ListView带来任何东西,第二个没有编译。

我做错了什么?

1 个答案:

答案 0 :(得分:0)

我找到了一个关于此问题和IT工作的解决方法!!!

(无论如何,你们告诉我这是否是最好的方法)

private void storeTesting(object sender, TextChangedEventArgs e)
    {
        List<Stores> storeTest = new List<Stores>();
        try
        {
            if (searchKeyword.Text != "")
            {
                Debug.WriteLine(searchKeyword.Text);

                foreach (Stores storeToShow in storesSource)
                {
                    if (storeToShow.Name.Contains(searchKeyword.Text))
                    {
                        storeTest.Add(storeToShow);
                    }
                }
            }
            else
            {
                Debug.WriteLine(searchKeyword.Text + "the text is null");
            }
        }
        catch (Exception ex)
        {
            Debug.WriteLine(ex.ToString());
        }

        var alphaKeyGroup = AlphaKeyGroup<Stores>.CreateGroups(storeTest, (Stores s) => { return s.Name; }, true);
        ListViewCollectionSource.Source = alphaKeyGroup;
    }
相关问题