private void SearchBar_OnTextChanged(object sender, TextChangedEventArgs e) { //thats all you need to make a search if (string.IsNullOrEmpty(e.NewTextValue)) { ProductsList.ItemsSource = ProdList; } else { tempdata2 = new List <Product>(); foreach (var prod in ProdList) { if (prod.Item1.Name.ToLower().Contains(e.NewTextValue.ToLower())) { tempdata2.Add(prod.Item1); prod.Item2.IsVisible = false; } if (prod.Item2.Name.ToLower().Contains(e.NewTextValue.ToLower())) { tempdata2.Add(prod.Item2); prod.Item1.IsVisible = false; } } l1 = new List <ProductPair>(); for (int i = 0; i <= tempdata2.Count; i = i + 2) { if (i < tempdata2.Count - 1) { ProductPair pp = new ProductPair(tempdata2[i], tempdata2[i + 1]); l1.Add(pp); } else if (i == tempdata2.Count - 1) { ProductPair pp = new ProductPair(tempdata2[i], null); l1.Add(pp); } } ProductsList.ItemsSource = l1; } }
void getdatabycategory(string category) { tempdata2 = new List <Product>(); foreach (var prod in ProdList) { if (prod.Item1.Category.Equals(category)) { tempdata2.Add(prod.Item1); prod.Item2.IsVisible = false; } if (prod.Item2.Category.Equals(category)) { tempdata2.Add(prod.Item2); prod.Item1.IsVisible = false; } } l1 = new List <ProductPair>(); for (int i = 0; i <= tempdata2.Count; i = i + 2) { if (i < tempdata2.Count - 1) { ProductPair pp = new ProductPair(tempdata2[i], tempdata2[i + 1]); l1.Add(pp); } else if (i == tempdata2.Count - 1) { ProductPair pp = new ProductPair(tempdata2[i], null); l1.Add(pp); } } ProductsList.ItemsSource = l1; }