コード例 #1
0
        private async void InitializeCategory()
        {
            Categories = await api.GetSubCategoriesFromParent(Id);

            var ParentCat = await api.GetCategoryById(Id);

            CategoryPivot.Title = ParentCat.Name.ToUpper();
            Currency            = await api.GetCurrency();

            if (Categories.Count() == 0)
            {
                ToggleBar(true);
                try
                {
                    var Products = await api.GetAllProductsFromCategory(Id);

                    var Page = new PivotItem();
                    Page.Header = "all products";
                    CategoryPivot.Items.Add(Page);
                    var Control = new ListBox();
                    Control.ItemContainerStyle = Application.Current.Resources["NoSelectColor"] as Style;
                    Control.ItemsPanel         = Application.Current.Resources["ProductCategoryWrapper"] as ItemsPanelTemplate;
                    Control.ItemTemplate       = Application.Current.Resources["ProductCategoryTemplate"] as DataTemplate;
                    foreach (ProductDTO p in Products)
                    {
                        Control.Items.Add(new MainPage.ProductData {
                            Id = p.Id, Description = p.Description, Image = Helper.ConvertToBitmapImage(p.Image.First()), ProductName = p.Name, Value = p.Price.ToString("0.0#") + " " + Currency
                        });
                    }
                    Control.SelectionChanged += Control_SelectionChanged;

                    Page.Content = Control;
                }
                catch (Exception ex)
                {
                }
            }
            else
            {
                foreach (CategoryDTO c in Categories)
                {
                    var CatList = new ListBox();
                    CatList.ItemContainerStyle = Application.Current.Resources["NoSelectColor"] as Style;
                    CatList.ItemsPanel         = Application.Current.Resources["ProductCategoryWrapper"] as ItemsPanelTemplate;

                    var Page = new PivotItem();
                    Page.Header = c.Name.ToLower();
                    CategoryPivot.Items.Add(Page);
                    var SubCats = await api.GetSubCategoriesFromParent(c.Id);

                    if (SubCats.Count() == 0)
                    {
                        if (Categories.First().Equals(c))
                        {
                            ToggleBar(true);
                        }
                        CatList.ItemTemplate = Application.Current.Resources["ProductCategoryTemplate"] as DataTemplate;
                        var Products = await api.GetAllProductsFromCategory(c.Id);

                        foreach (ProductDTO p in Products)
                        {
                            CatList.Items.Add(new MainPage.ProductData {
                                Id = p.Id, Description = p.Description, Image = Helper.ConvertToBitmapImage(p.Image.First()), ProductName = p.Name, Value = p.Price.ToString("0.0#") + " " + Currency
                            });
                        }
                        CatList.SelectionChanged += Control_SelectionChanged;
                    }
                    else
                    {
                        CatList.ItemTemplate = Application.Current.Resources["CategoryTemplate"] as DataTemplate;
                        foreach (CategoryDTO subC in SubCats)
                        {
                            CatList.Items.Add(new MainPage.CategoryData {
                                Id = subC.Id, Image = Helper.ConvertToBitmapImage(subC.Image), Name = subC.Name
                            });
                        }
                    }
                    Page.Content = CatList;
                }
            }
            Initialized = true;
        }