From 7f1640b329f5129002de3fceb379bdd4011f10ac Mon Sep 17 00:00:00 2001 From: Loris OBRY Date: Wed, 24 May 2023 09:56:37 +0200 Subject: [PATCH] Modification OnPropertyCHanched avec CallerMemberName et ajout des onPrepertychanged --- Sources/Model/Carte.cs | 68 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 55 insertions(+), 13 deletions(-) diff --git a/Sources/Model/Carte.cs b/Sources/Model/Carte.cs index 0d9ecc7..9479b48 100644 --- a/Sources/Model/Carte.cs +++ b/Sources/Model/Carte.cs @@ -4,16 +4,48 @@ using System.Globalization; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.ComponentModel; +using System.Runtime.CompilerServices; namespace Model { - public class Carte + public class Carte : INotifyPropertyChanged { + public event PropertyChangedEventHandler? PropertyChanged; + void OnPropertyChanged([CallerMemberName] string ?propertyName = null) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + private readonly string nom; - public string Nom => nom; - public string Description { get; set; } - public string Pouvoir { get; set;} - public string Strategies { get; set; } + public string Nom => nom; + public string Description { + get => description; + set { + description = value; + OnPropertyChanged(nameof(Description)); + } + } + private string description; + public string Pouvoir { + get => pouvoir; + set + { + pouvoir = value; + OnPropertyChanged(nameof(Pouvoir)); + } + } + private string pouvoir; + public string Strategie + { + get => strategie; + set + { + strategie = value; + OnPropertyChanged(nameof(Strategie)); + } + } + private string strategie; private int? note; public int? Note { @@ -28,18 +60,28 @@ namespace Model throw new ArgumentOutOfRangeException(nameof(value), "La valeur de la note doit ĂȘtre comprise entre 0 et 10."); } note = value; + OnPropertyChanged(nameof(Note)); + } + } + public string LienImage + { + get => lienImage; + set + { + if (!string.IsNullOrEmpty(lienImage)) lienImage = "notfound"; + else lienImage = value; + OnPropertyChanged(nameof(LienImage)); } } - public string LienImage { get; set; } = "notFound"; - - public Carte(string nom, string pouvoir, string strategies, int? note, string lienImage, string description) + private string lienImage; + public Carte(string nom, string pouvoir, string strategie, int? note, string lienImage, string description) { this.nom = nom; - Description = description; - Pouvoir = pouvoir; - Strategies = strategies; - Note = note; - LienImage = lienImage; + this.description = description; + this.pouvoir = pouvoir; + this.strategie = strategie; + this.note = note; + this.lienImage = LienImage; } } }