Reputation: 1016
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?
Upvotes: 2
Views: 1065
Reputation: 1414
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();
}
Upvotes: 3
Reputation: 1016
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
Upvotes: 0