示例#1
0
        private void SearchBar_OnTextChanged(object sender, TextChangedEventArgs e)
        {
            //thats all you need to make a search

            if (string.IsNullOrEmpty(e.NewTextValue))
            {
                ListProducts.ItemsSource = tempdata;
            }

            else
            {
                tempdata2 = new List <Product>();

                foreach (var prod in tempdata)
                {
                    if (prod.Item1.Designation.ToLower().Contains(e.NewTextValue.ToLower()))
                    {
                        tempdata2.Add(prod.Item1);
                        prod.Item2.IsVisible = false;
                    }

                    if (prod.Item2.Designation.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);
                    }
                }

                ListProducts.ItemsSource = l1;
            }
        }
示例#2
0
        void getdatabycategory(string category)
        {
            tempdata2 = new List <Product>();

            foreach (var prod in tempdata)
            {
                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);
                }
            }

            ListProducts.ItemsSource = l1;
        }