Пример #1
0
 private void RemoveCategory_Click(object sender, RoutedEventArgs e)
 {
     if (sender is Button button && button.DataContext is Category category)
     {
         CategoryListViewModel vm = DataContext as CategoryListViewModel;
         App.AvailableCategories.Remove(category);
         vm.ForceUpdateList();
     }
 }
Пример #2
0
        private void AddCategory_Click(object sender, RoutedEventArgs e)
        {
            CategoryListViewModel vm = DataContext as CategoryListViewModel;

            if (!vm.AvailableCategories.Any(x => x.Name.Equals(vm.NewCategoryName, StringComparison.InvariantCultureIgnoreCase)))
            {
                App.AvailableCategories.Add(new Category(vm.NewCategoryName));
                vm.NewCategoryName = "";
                vm.ForceUpdateList();
            }
        }
Пример #3
0
        private void AddCategories_Click(object sender, RoutedEventArgs e)
        {
            CategoryListViewModel vm = DataContext as CategoryListViewModel;

            string[] categories = vm.CategoryListRaw.Replace("\r\n", "\n").Replace('\r', '\n').Split('\n');

            foreach (string ingredient in categories)
            {
                if (!vm.AvailableCategories.Any(x => x.Name.Equals(ingredient, StringComparison.InvariantCultureIgnoreCase)))
                {
                    App.AvailableCategories.Add(new Category(ingredient));
                }
            }

            vm.CategoryListRaw = "";
            vm.ForceUpdateList();
        }