コード例 #1
0
        private async void GetStoreSaleItems(Store store)
        {
            this.purchaseList.Clear();
            this.storeItemList = null;
            this.storeItemList = await connection.GetStoreSaleItems(store, this);

            // Reset TabItems visibility and remove children
            this.FoodTabItem.Visibility       = Visibility.Hidden;
            this.BeverageTabItem.Visibility   = Visibility.Hidden;
            this.HouseholdTabItem.Visibility  = Visibility.Hidden;
            this.ElectronicTabItem.Visibility = Visibility.Hidden;
            this.FoodWrapPanel.Children.Clear();
            this.BeverageWrapPanel.Children.Clear();
            this.HouseholdWrapPanel.Children.Clear();
            this.ElectronicWrapPanel.Children.Clear();

            // Add StoreSaleItems as Tiles to TabItems by ItemType
            foreach (StoreSaleItem ssi in this.storeItemList)
            {
                ImageBrush  brush;
                BitmapImage bi;
                using (var ms = new MemoryStream(ssi.ItemPicture))
                {
                    brush = new ImageBrush();
                    bi    = new BitmapImage();
                    bi.BeginInit();
                    bi.CreateOptions = BitmapCreateOptions.None;
                    bi.CacheOption   = BitmapCacheOption.OnLoad;
                    bi.StreamSource  = ms;
                    bi.EndInit();
                }
                brush.ImageSource = bi;
                Tile tile = new Tile
                {
                    Title      = ssi.ItemName,
                    Count      = "\u20AC" + ssi.StoreSaleItemPrice.ToString(),
                    Foreground = Brushes.Black,
                    Background = brush,
                    Tag        = ssi.ItemId,
                };
                tile.Click += AddToPurchaseList_Click;

                // Make TabItem visible at first Tile added. Empty TabItems will remain hidden.
                switch (ssi.ItemTypeId)
                {
                case 1:
                    if (!this.FoodTabItem.IsVisible)
                    {
                        this.FoodTabItem.Visibility = Visibility.Visible;
                    }
                    this.FoodWrapPanel.Children.Add(tile);
                    break;

                case 2:
                    if (!this.BeverageTabItem.IsVisible)
                    {
                        this.BeverageTabItem.Visibility = Visibility.Visible;
                    }
                    this.BeverageWrapPanel.Children.Add(tile);
                    break;

                case 3:
                    if (!this.HouseholdTabItem.IsVisible)
                    {
                        this.HouseholdTabItem.Visibility = Visibility.Visible;
                    }
                    this.HouseholdWrapPanel.Children.Add(tile);
                    break;

                case 4:
                    if (!this.ElectronicTabItem.IsVisible)
                    {
                        this.ElectronicTabItem.Visibility = Visibility.Visible;
                    }
                    this.ElectronicWrapPanel.Children.Add(tile);
                    break;
                }
            }
        }