From 6e88c66e20b1e3263147a4eb2126cf9beed6aee0 Mon Sep 17 00:00:00 2001 From: Matheo HERSAN Date: Mon, 22 May 2023 11:51:39 +0200 Subject: [PATCH 1/4] Continue DataBinding --- .../DataBinding/INotifyPropertyChanged.cs | 14 +++++++++ MangaMap/Views/FicheAnime.xaml.cs | 31 +++++++++++++++---- MangaMap/Views/ficheAnime.xaml | 19 ++++++------ 3 files changed, 49 insertions(+), 15 deletions(-) create mode 100644 MangaMap/DataBinding/INotifyPropertyChanged.cs diff --git a/MangaMap/DataBinding/INotifyPropertyChanged.cs b/MangaMap/DataBinding/INotifyPropertyChanged.cs new file mode 100644 index 0000000..0914cc6 --- /dev/null +++ b/MangaMap/DataBinding/INotifyPropertyChanged.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MangaMap.DataBinding +{ + public interface INotifyPropertyChanged + { + public event PropertyChangedEventHandler? PropertyChanged; + } +} diff --git a/MangaMap/Views/FicheAnime.xaml.cs b/MangaMap/Views/FicheAnime.xaml.cs index 11c6adc..d4f8e6a 100644 --- a/MangaMap/Views/FicheAnime.xaml.cs +++ b/MangaMap/Views/FicheAnime.xaml.cs @@ -1,18 +1,37 @@ namespace MangaMap.Views; using Model; +using System.ComponentModel; -public partial class ficheAnime : ContentPage +public partial class ficheAnime : ContentPage, INotifyPropertyChanged { - public Oeuvre AnimeModel { get; set; } + private Oeuvre animeModel; + public Oeuvre AnimeModel + { + get { return animeModel; } + set + { + if (animeModel != value) + { + animeModel = value; + OnPropertyChanged(nameof(AnimeModel)); + } + } + } public ficheAnime() { - InitializeComponent(); - - // Exemple de création d'une instance de la classe Oeuvre List genres = new List() { "Action", "Aventure" }; - AnimeModel = new Oeuvre("Nom de l'oeuvre", genres, "Type de l'oeuvre", "Description de l'oeuvre", 5, 12, "Chemin/vers/l'affiche.png"); + AnimeModel = new Oeuvre("Evangelion", genres, "Type de l'oeuvre", "Description de l'oeuvre", 5, 12, "Chemin/vers/l'affiche.png"); + + InitializeComponent(); this.BindingContext = this; } + + public event PropertyChangedEventHandler PropertyChanged; + + protected virtual void OnPropertyChanged(string propertyName) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } } \ No newline at end of file diff --git a/MangaMap/Views/ficheAnime.xaml b/MangaMap/Views/ficheAnime.xaml index 7b60d09..0254262 100644 --- a/MangaMap/Views/ficheAnime.xaml +++ b/MangaMap/Views/ficheAnime.xaml @@ -12,14 +12,15 @@ - - - @@ -46,7 +47,7 @@ Text="Je suis une description. Je suis une description. Je suis une description. Je suis une description. Je suis une description. Je suis une description. Je suis une description. Je suis une description. Je suis une description. Je suis une description." Margin="20"/> -