Beispiel #1
0
        public static ObservableCollection <ShopCategory> CreateShop()
        {
            ObservableCollection <ShopCategory> list = new ObservableCollection <ShopCategory>();
            ShopCategory books  = new ShopCategory("Books");
            ShopCategory movies = new ShopCategory("Movies");
            ShopCategory music  = new ShopCategory("Music");

            //root categories
            list.Add(books);
            list.Add(movies);
            list.Add(music);

            //2nd level items on all categories
            books.SubCategories.Add(new ShopCategory("Fiction", books));
            books.SubCategories.Add(new ShopCategory("Travel", books));
            books.SubCategories.Add(new ShopCategory("Politics", books));

            movies.SubCategories.Add(new ShopCategory("Action", movies));
            movies.SubCategories.Add(new ShopCategory("Fantasy", movies));
            movies.SubCategories.Add(new ShopCategory("Romance", movies));
            movies.SubCategories.Add(new ShopCategory("Horror", movies));

            music.SubCategories.Add(new ShopCategory("Pop", music));
            music.SubCategories.Add(new ShopCategory("Techno", music));
            music.SubCategories.Add(new ShopCategory("Classical", music));
            music.SubCategories.Add(new ShopCategory("Ethno", music));
            ShopCategory rock = new ShopCategory("Rock", music);

            music.SubCategories.Add(rock);

            //get 3rd level on rock
            rock.SubCategories.Add(new ShopCategory("Alternative", rock));
            rock.SubCategories.Add(new ShopCategory("Metal", rock));
            rock.SubCategories.Add(new ShopCategory("Industrial Rock", rock));



            return(list);
        }
Beispiel #2
0
        public ShopCategory TryFindCategoryByName(ShopCategory parent, string categoryName)
        {
            ObservableCollection <ShopCategory> cats;

            cats = parent == null ? categories : parent.SubCategories;
            foreach (ShopCategory category in cats)
            {
                if (category.CategoryName == categoryName)
                {
                    return(category);
                }
                else
                {
                    ShopCategory cat = TryFindCategoryByName(category, categoryName);
                    if (cat != null)
                    {
                        return(cat);
                    }
                }
            }

            return(null);
        }
Beispiel #3
0
 /// <summary>
 /// Creates a category for a given parent. This sets the
 /// <see cref="ParentCategory"/> reference, but does not
 /// automatically add the category to the parent's
 /// <see cref="SubCategories"/> collection.
 /// </summary>
 /// <param name="categoryName">The category's name.</param>
 /// <param name="parentCategory">The parent category, if any.</param>
 public ShopCategory(string categoryName, ShopCategory parentCategory)
 {
     this.categoryName   = categoryName;
     this.parentCategory = parentCategory;
 }