Example #1
0
 private void RemoveIngredient_Click(object sender, RoutedEventArgs e)
 {
     if (sender is Button button && button.DataContext is Ingredient ingredient)
     {
         IngredientListViewModel vm = DataContext as IngredientListViewModel;
         App.AvailableIngredients.Remove(ingredient);
         vm.ForceUpdateList();
     }
 }
Example #2
0
        private void AddIngredient_Click(object sender, RoutedEventArgs e)
        {
            IngredientListViewModel vm = DataContext as IngredientListViewModel;

            if (!vm.AvailableIngredients.Any(x => x.Name.Equals(vm.NewIngredientName, StringComparison.InvariantCultureIgnoreCase)))
            {
                App.AvailableIngredients.Add(new Ingredient(vm.NewIngredientName));
                vm.NewIngredientName = "";
                vm.ForceUpdateList();
            }
        }
Example #3
0
        private void AddIngredients_Click(object sender, RoutedEventArgs e)
        {
            IngredientListViewModel vm = DataContext as IngredientListViewModel;

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

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

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