using Microsoft.Maui.Controls; namespace ShoopNCook.Views; public partial class RecipePage : ContentPage { private uint nbPers; private bool isFavorite; public RecipePage() : this("Recipe Sample", 32, 250, true, 1, new List { new IngredientView("Chocolate", 25, "g"), new IngredientView("Flour", 250, "g"), new IngredientView("Sugar", 0.5F, "kg") }, new List { "This is the first preparation step", "add to furnace and wait", "Enjoy !" } ) {} public RecipePage( string name, uint cookTime, uint energy, bool isFavorite, uint nbPers, List ingredients, List steps ) { InitializeComponent(); this.nbPers = nbPers; this.isFavorite = isFavorite; CookTime.Text = cookTime.ToString(); Energy.Text = energy.ToString(); RecipeName.Text = name; foreach (IngredientView iv in ingredients) IngredientList.Add(iv); var styles = Application.Current.Resources.MergedDictionaries.ElementAt(1); int count = 0; foreach (string step in steps) { Label label = new Label(); label.Style = (Style)styles["Small"]; label.Text = "Step " + ++count + ": " + step; StepList.Add(label); } } private void OnFavorite(object o, EventArgs e) { isFavorite = !isFavorite; if (isFavorite) { Favorite.Source = ImageSource.FromFile("earth_on.svg"); } else { Favorite.Source = ImageSource.FromFile("earth_off.svg"); } } private void OnPlus(object o, EventArgs e) { UpdateCounter(++nbPers); } private void OnMinus(object o, EventArgs e) { if (nbPers <= 1) return; nbPers--; UpdateCounter(nbPers); } private void UpdateCounter(uint counter) { NbPersLabel.Text = counter.ToString(); } }