How Would I Search Data From Xamarin. Forms List View Using Search Bar In MVVM Pattern.

How Would I Search Data From Xamarin. Forms List View Using Search Bar In MVVM Pattern.I have tried Something only for the first time it's refreshing the list next time when i change the search text it's showing empty can someone help me in this issue Thank you.

Best Answers

  • vinodkumarpachimadlavinodkumarpachimadla USMember ✭✭
    Accepted Answer

    private void SearchBar_TextChanged(object sender, TextChangedEventArgs e)
    {
    var vm = BindingContext as ListOfFlatsViewModel;
    NameListOfFlatsList.BeginRefresh();

            if (string.IsNullOrWhiteSpace(e.NewTextValue))
    
                NameListOfFlatsList.ItemsSource = vm.ListOfFlatsList;
            else
                NameListOfFlatsList.ItemsSource = vm.ListOfFlatsList.Where(i => i.Address.Contains(e.NewTextValue.ToLower()));
    
            NameListOfFlatsList.EndRefresh();
        }
    

Answers

  • Thank you so much @Mabrouk It's Working Fine.

  • vinodkumarpachimadlavinodkumarpachimadla USMember ✭✭
    Accepted Answer

    private void SearchBar_TextChanged(object sender, TextChangedEventArgs e)
    {
    var vm = BindingContext as ListOfFlatsViewModel;
    NameListOfFlatsList.BeginRefresh();

            if (string.IsNullOrWhiteSpace(e.NewTextValue))
    
                NameListOfFlatsList.ItemsSource = vm.ListOfFlatsList;
            else
                NameListOfFlatsList.ItemsSource = vm.ListOfFlatsList.Where(i => i.Address.Contains(e.NewTextValue.ToLower()));
    
            NameListOfFlatsList.EndRefresh();
        }
    
Sign In or Register to comment.