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); } }
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; }