From 14465aecfe0bec8c86fe570353baeb1868eae33d Mon Sep 17 00:00:00 2001 From: Roxane Date: Fri, 9 Jun 2023 18:57:41 +0200 Subject: [PATCH] Fix binding on MyProfil finished. Add all bindings on AddRecipe page, remain only the validation button to add the new recipe to our datafile --- MCTG/Model/Recipes/Ingredient/Ingredient.cs | 20 ++- MCTG/Model/Recipes/Recipe.cs | 4 +- MCTG/Views/ContentPages/AddRecipe.xaml | 131 ++++++++++++-------- MCTG/Views/ContentPages/AddRecipe.xaml.cs | 130 ++++++++++++++++--- MCTG/Views/ContentPages/ViewRecette.xaml | 113 ++++++++--------- 5 files changed, 262 insertions(+), 136 deletions(-) diff --git a/MCTG/Model/Recipes/Ingredient/Ingredient.cs b/MCTG/Model/Recipes/Ingredient/Ingredient.cs index c8452d8..7fed257 100644 --- a/MCTG/Model/Recipes/Ingredient/Ingredient.cs +++ b/MCTG/Model/Recipes/Ingredient/Ingredient.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; +using System.Runtime.CompilerServices; using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; @@ -8,7 +10,7 @@ using System.Threading.Tasks; namespace Model { [DataContract(Name = "ingredient")] - public class Ingredient + public class Ingredient : INotifyPropertyChanged { #region Attributes [DataMember(Name = "id")] @@ -17,6 +19,7 @@ namespace Model [DataMember(Name = "quantity")] private Quantity _quantity = new Quantity(1, Unit.unit); + public event PropertyChangedEventHandler? PropertyChanged; #endregion #region Properties @@ -33,6 +36,7 @@ namespace Model throw new ArgumentNullException("Impossible de ne pas avoir de nom pour l'ingrédient"); } _name = value; + OnPropertyChanged(); } } @@ -41,8 +45,12 @@ namespace Model /// public Quantity QuantityI { - get => _quantity; - set => _quantity = value; + get { return _quantity; } + set + { + _quantity = value; + OnPropertyChanged(); + } } @@ -62,6 +70,12 @@ namespace Model Name = name; QuantityI = quantity; } + protected void OnPropertyChanged([CallerMemberName] string? propertyName = null) + { + if (PropertyChanged != null) + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + #endregion public override string ToString() diff --git a/MCTG/Model/Recipes/Recipe.cs b/MCTG/Model/Recipes/Recipe.cs index 9c48274..5697148 100644 --- a/MCTG/Model/Recipes/Recipe.cs +++ b/MCTG/Model/Recipes/Recipe.cs @@ -56,7 +56,7 @@ namespace Model /// Priority of this recipe. /// [DataMember(Name = "priority")] - public Priority Priority { get; private set; } + public Priority Priority { get; set; } /// /// The Title of the recipe.
@@ -107,7 +107,7 @@ namespace Model /// The type of recipe. ///
[DataMember(Name = "type")] - public RecipeType Type { get; private set; } + public RecipeType Type { get; set; } #endregion #region Constructors diff --git a/MCTG/Views/ContentPages/AddRecipe.xaml b/MCTG/Views/ContentPages/AddRecipe.xaml index b8ddf9c..bae9437 100644 --- a/MCTG/Views/ContentPages/AddRecipe.xaml +++ b/MCTG/Views/ContentPages/AddRecipe.xaml @@ -3,68 +3,91 @@ xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Views.AddRecipe" Title="AddRecipe" - xmlns:local="clr-namespace:Views"> - - + + + - -