Пример #1
0
 private void CloseCategory(object sender, EventArgs e)
 {
     if (sender is CategoryVM category)
     {
         var selectedIndex = OpenCategories.IndexOf(category);
         if (category == SelectedCategory)
         {
             SelectedCategory = selectedIndex > 1
                 ? OpenCategories[selectedIndex - 1]
                 : OpenCategories.FirstOrDefault();
         }
         OpenCategories.Remove(category);
     }
 }
Пример #2
0
        private void OpenCategory(CategoryVM category)
        {
            if (OpenCategories.Contains(category))
            {
                SelectedCategory = category;
                return;
            }

            if (category.IsProductsLoaded == false || category.Products.Any() == false)
            {
                LoadProducts(category);
                category.Close += CloseCategory;
            }

            OpenCategories.Add(category);
            SelectedCategory = category;
        }