Xamarin:ListView 搜索大写还是小写

Xamarin: ListView search whether Uppercase or Lowercase

我正在创建搜索栏,但似乎无法返回结果。它似乎区分大小写。有什么方法可以让它不区分大小写,以便用户可以搜索小写或大写并获得相同的结果?

这是我的代码提前致谢!

  void SearchBar_TextChanged(object sender, TextChangedEventArgs e)
    {
        var _Container = BindingContext as PageViewModel;
        MyListView.BeginRefresh();

        if (String.IsNullOrWhiteSpace(e.NewTextValue))
            MyListView.ItemsSource = _Container.MyPageDetailCollection;
        else
            MyListView.ItemsSource = _Container.MyPageDetailCollection.Where(i => i.Name.Contains(e.NewTextValue));
        MyListView.EndRefresh();

    }

我们可以先将输入的字符串转换成小写字符串。

您可以参考以下代码:

string queryString = e.NewTextValue;

var normalizedQuery = queryString?.ToLower() ?? "";

MyListView.ItemsSource = _Container.MyPageDetailCollection.Where(f => f.Name.ToLowerInvariant().Contains(normalizedQuery)).ToList();

在执行“where”LINQ 查询之前考虑将字符串转换为 lowercase/uppercase,如下所示:

void SearchBar_TextChanged(object sender, TextChangedEventArgs e)
{
    var _Container = BindingContext as PageViewModel;
    MyListView.BeginRefresh();

    if (String.IsNullOrWhiteSpace(e.NewTextValue))
        MyListView.ItemsSource = _Container.MyPageDetailCollection;
    else
        MyListView.ItemsSource = _Container.MyPageDetailCollection.Where(i => i.Name.ToLower().Contains(e.NewTextValue.ToLower()));
    MyListView.EndRefresh();

}