Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Listview 如何在Xamarin表单的条目中实现搜索建议_Listview_Xamarin.forms_Xamarin.forms.entry - Fatal编程技术网

Listview 如何在Xamarin表单的条目中实现搜索建议

Listview 如何在Xamarin表单的条目中实现搜索建议,listview,xamarin.forms,xamarin.forms.entry,Listview,Xamarin.forms,Xamarin.forms.entry,我需要实现一个建议框,为此,我放置了一个条目来接受关键字,正好在我使用Listview显示建议的下方。Listview中已经有数据源和一些条目。现在我想像这样实现它- “例如,如果关键词是: 牛奶 肉 奶油 当用户在“m”中键入时,奶油被过滤掉,只显示牛奶和肉,因为它们以“m”开头。当用户在“mi”中键入时,肉也被过滤掉,只显示牛奶。给你 var list = new List<string> { "Milk", "Cream", "Meat" };

我需要实现一个建议框,为此,我放置了一个条目来接受关键字,正好在我使用Listview显示建议的下方。Listview中已经有数据源和一些条目。现在我想像这样实现它-

“例如,如果关键词是:

  • 牛奶
  • 奶油
当用户在“m”中键入时,奶油被过滤掉,只显示牛奶和肉,因为它们以“m”开头。当用户在“mi”中键入时,肉也被过滤掉,只显示牛奶。给你

       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 }
                }

            };
var list=新列表{“牛奶”、“奶油”、“肉”};
var myListView=新建ListView();
myListView.ItemsSource=列表;
var entry=新条目();
entry.TextChanged+=委托(对象发送方,textchangedventargs args)
{
if(string.IsNullOrEmpty(entry.Text))
{
myListView.ItemsSource=列表;
} 
其他的
{
myListView.ItemsSource=列表
.其中(x=>x.ToLower()
.StartsWith(entry.Text.ToLower());
}
};
主页=新内容页()
{
内容=新的StackLayout()
{
Children={entry,myListView}
}
};

通过将其更改为以下内容,可以使其不区分大小写:

myListView.ItemsSource = list.Where(x => x.ToLower().StartsWith(entry.Text.ToLower())); 

您好TheMoFaDe,这是一个非常好的解决方案,但我面临的一个问题是,它只显示小写字母的结果,而不显示大写字母的结果。它不应该区分大小写。如果用户输入“m”或“m”,它应该给出以“m”或“m”开头的所有项目的列表,反之亦然。我通过替换myListView.ItemsSource=list来解决它。其中(x=>x.ToLower().StartsWith(entry.Text))-----with-----myListView.ItemsSource=list.Where(x=>x.StartWith(entry.Text));------但它是区分大小写的。我不知道怎么区分大小写。