我需要实现一个建议框,为此,我放置了一个条目来接受关键字,就在下面,我使用Listview来显示建议。Listview已经有了DataSource和其中的一些条目。现在我想把它实现得像-
“例如,如果关键词是:
当用户键入“m”时,奶油被过滤掉,只显示牛奶和肉类,因为它们以“m”开头。当用户键入“mi”时,“肉类”也会被过滤掉,只显示“牛奶”。
发布于 2016-06-08 19:28:55
这就是你要的
var list = new List<string> { "Milk", "Cream", "Meat" };
var myListView = new ListView();
myListView.ItemsSource = list;
var entry = new Entry();
entry.TextChanged += delegate(object sender, TextChangedEventArgs args)
{
if (string.IsNullOrEmpty(entry.Text))
{
myListView.ItemsSource = list;
}
else
{
myListView.ItemsSource = list
.Where(x => x.ToLower()
.StartsWith(entry.Text.ToLower()));
}
};
MainPage = new ContentPage()
{
Content = new StackLayout()
{
Children = { entry, myListView }
}
};发布于 2016-09-17 02:30:28
通过将其更改为以下内容,可以使其不区分大小写:
myListView.ItemsSource = list.Where(x => x.ToLower().StartsWith(entry.Text.ToLower())); https://stackoverflow.com/questions/37703598
复制相似问题