ListView / List Filter Windows Phone 8.1 C#

ぐ巨炮叔叔 提交于 2019-12-07 20:52:15

问题


I have a list of data

public class PopImage
{
    public async Task<List<PopImage>> PopDatas()
    {
        string imgfolder = "PopularImages";
        var data = new List<PopImage>();
        StorageFolder folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
        StorageFolder subfolder = await folder.GetFolderAsync(imgfolder);

        var files = await subfolder.GetFilesAsync();
        foreach (var items in files)
        {
            data.Add(new PopImage(imgfolder+"/"+items.DisplayName+ ".jpg", items.DisplayName));
        }

        return data;
    }

    public PopImage(string imagePath, string imageName)
    {
        ImagePath = imagePath;
        ImageName = imageName;
    }

    public string ImagePath { get; set; }
    public string ImageName { get; set; }
}

I want to add a textbox and filter it if textbox textchanged, what do I need to apply it?


回答1:


You need to add a TextChanged event to your TextBox. First in your XAML add this:

<TextBox Name="tbListFilter" TextChanged="tbListFilter_TextChanged"/>

Then the code behind is:

private void tbListFilter_TextChanged(object sender, TextChangedEventArgs e)
{
     yourFilteredList = yourPopImageList.Where(p => p.ImageName.ToUpper().Contains(tbListFilter.Text.ToUpper())).ToList();
}



回答2:


Based on @WPMed

I try to make a new list from filtered items

var FilteredList= new List<PopImage>();
        foreach (var data in popimagelist)
        {
            if(data.ImageName.ToUpper().Contains(FilterText.Text.ToUpper()))FilteredList.Add(data);
        }

Thank you for the help



来源:https://stackoverflow.com/questions/29441433/listview-list-filter-windows-phone-8-1-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!