private async Task FilterCustomerList()

in ContosoApp/Views/CustomerListPage.xaml.cs [139:165]


        private async Task FilterCustomerList(string text)
        {
            string[] parameters = text.Split(new char[] { ' ' },
                StringSplitOptions.RemoveEmptyEntries);

            var matches = ViewModel.Customers.Where(customer => parameters
                .Any(parameter =>
                    customer.Address.StartsWith(parameter, StringComparison.OrdinalIgnoreCase) ||
                    customer.FirstName.StartsWith(parameter, StringComparison.OrdinalIgnoreCase) ||
                    customer.LastName.StartsWith(parameter, StringComparison.OrdinalIgnoreCase) ||
                    customer.Company.StartsWith(parameter, StringComparison.OrdinalIgnoreCase)))
                .OrderByDescending(customer => parameters.Count(parameter =>
                    customer.Address.StartsWith(parameter) ||
                    customer.FirstName.StartsWith(parameter) ||
                    customer.LastName.StartsWith(parameter) ||
                    customer.Company.StartsWith(parameter)))
                .ToList();

            await dispatcherQueue.EnqueueAsync(() =>
            {
                ViewModel.Customers.Clear();
                foreach (var match in matches)
                {
                    ViewModel.Customers.Add(match);
                }
            });
        }