我有数据清单
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; }
}
我想添加一个文本框并对其进行过滤(如果文本框已更改),
我需要申请什么?
最佳答案
您需要将TextChanged事件添加到TextBox中。
首先在您的XAML中添加以下内容:
<TextBox Name="tbListFilter" TextChanged="tbListFilter_TextChanged"/>
那么后面的代码是:
private void tbListFilter_TextChanged(object sender, TextChangedEventArgs e)
{
yourFilteredList = yourPopImageList.Where(p => p.ImageName.ToUpper().Contains(tbListFilter.Text.ToUpper())).ToList();
}