public MainPage() { InitializeComponent(); SearchIngredients = new List <IngredientDtoV2>(); MyIngredients = User.User.SavedIngredinets; foreach (var ingredient in MyIngredients) { MyIngredientModels.Add(new IngredientListModel() { Ingredient = ingredient, IsAdded = true }); } ExcludedIngredients = User.User.SavedExcludedIngredinets; foreach (var ingredient in ExcludedIngredients) { ExcludedIngredientModels.Add(new IngredientListModel() { Ingredient = ingredient, IsAdded = true }); } NoIngredientsError = false; XamlSetup(); BindingContext = this; }
void MyIngredientsRemoveAt(int index) { MyIngredients.RemoveAt(index); if (!InSearchWindow) { MyIngredientModels.RemoveAt(index); Sorting.ResizeListView(ListView_myIngredients, MyIngredients.Count); } SaveMyIngredients(MyIngredients); }
void MyIngredientsAdd(IngredientDtoV2 ingredient) { MyIngredients.Insert(0, ingredient); if (!InSearchWindow) { Sorting.ResizeListView(ListView_myIngredients, MyIngredients.Count); MyIngredientModels.Insert(0, new IngredientListModel() { Ingredient = ingredient }); } SaveMyIngredients(MyIngredients); }
// --------------------------------------------- SPAGHETTI --------------------------------------------------- void GenerateMyIngredientModels() { MyIngredientModels.Clear(); foreach (var ingredient in MyIngredients) { MyIngredientModels.Add(new IngredientListModel { Ingredient = ingredient, IsAdded = true }); } Sorting.ResizeListView(ListView_myIngredients, MyIngredients.Count); }
// Clicked in myIngredients list private void ListView_myIngredients_ItemSelected(object sender, SelectedItemChangedEventArgs e) { MyIngredientsRemoveAt(MyIngredientModels.IndexOf(ListView_myIngredients.SelectedItem as IngredientListModel)); }